Skip to content

SIFA Register Youth

This workflow provides a REST API endpoint for registering youth entrepreneurs in the SIFA program. It handles duplicate detection, phone number normalization, database insertion, and audit logging while providing appropriate responses for both successful registrations and duplicate attempts.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

How It Works

  1. Receive Registration Data: A POST request is made to the webhook endpoint with youth registration information
  2. Normalize Phone Number: The phone number is standardized to international format (+254 prefix for Kenyan numbers)
  3. Check for Duplicates: The system queries the database to see if a youth with the same phone number already exists
  4. Handle Duplicates: If a duplicate is found, the workflow responds with an error message including the existing youth's name
  5. Register New Youth: If no duplicate exists, the youth's information is inserted into the database
  6. Log the Registration: An audit log entry is created to track the registration event
  7. Confirm Success: A success response is sent back confirming the registration

Workflow Diagram

graph TD
    A[Webhook] --> B[Normalize Phone]
    B --> C[Check Duplicate]
    C --> D[Is Duplicate]
    D -->|Yes| E[Respond Duplicate]
    D -->|No| F[Insert Youth]
    F --> G[Log Registration]
    G --> H[Respond Success]

Trigger

  • Type: Webhook (HTTP POST)
  • Path: /sifa-register-youth
  • Method: POST
  • CORS: Enabled with Access-Control-Allow-Origin: *

Nodes Used

Node Type Node Name Purpose
Webhook Webhook Receives HTTP POST requests with youth registration data
Code Normalize Phone Standardizes phone numbers to international format
Postgres Check Duplicate Queries database to find existing registrations by phone number
If Is Duplicate Branches workflow based on whether a duplicate exists
Respond to Webhook Respond Duplicate Returns error response for duplicate registrations
Postgres Insert Youth Adds new youth record to the database
Postgres Log Registration Creates audit log entry for the registration
Respond to Webhook Respond Success Returns success confirmation

External Services & Credentials Required

PostgreSQL Database

  • Credential Name: "Postgres account"
  • Required Access: Read/Write permissions on:
    • youthEntrepreneursReal table
    • changeLogs table

Environment Variables

No environment variables are explicitly used in this workflow. All configuration is handled through n8n credentials and node parameters.

Data Flow

Input (POST Request Body)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
{
  "firstName": "string",
  "secondName": "string", 
  "phoneNumber": "string",
  "gender": "string",
  "age": "number",
  "county": "string",
  "ward": "string",
  "youthWard": "string",
  "businessOwned": "string",
  "recruiterName": "string",
  "preferredLanguage": "string",
  "channel": "string",
  "phoneType": "string"
}

Output Responses

Success Response:

1
2
3
4
{
  "status": "success",
  "message": "Youth [firstName] [secondName] registered successfully!"
}

Duplicate Response:

1
2
3
4
{
  "status": "duplicate", 
  "message": "Youth with phone number [phoneNumber] already exists in the database as [existingName]"
}

Error Handling

The workflow includes built-in error handling for:

  • Duplicate Registrations: Detected by querying existing phone numbers and returning a specific error response
  • Phone Number Normalization: Automatically converts various phone number formats to international standard
  • Database Errors: PostgreSQL node errors will cause the workflow to fail and can be caught by n8n's error handling

Known Limitations

  • Phone number normalization is specifically designed for Kenyan numbers (+254)
  • No validation of required fields beyond what the database schema enforces
  • CORS is set to allow all origins (*) which may not be suitable for production environments
  • No rate limiting or authentication on the webhook endpoint

No related workflows identified from the current context.

Setup Instructions

  1. Import the Workflow

    • Copy the workflow JSON
    • In n8n, go to Workflows → Import from JSON
    • Paste the JSON and save
  2. Configure PostgreSQL Credentials

    • Go to Credentials → Add Credential → Postgres
    • Enter your database connection details
    • Name it "Postgres account" (or update the credential references in nodes)
  3. Verify Database Schema Ensure these tables exist with appropriate columns:

    youthEntrepreneursReal table: - firstName, secondName, phoneNumber, gender, age - county, ward, youthWard, businessOwned, recruiterName - preferredLanguage, channel, phoneType

    changeLogs table: - recruiterName, recruiterRole, changeType - youthFirstName, youthSecondName, youthPhoneNumber - details (JSON field)

  4. Activate the Workflow

    • Click the toggle to activate
    • Note the webhook URL for integration
  5. Test the Integration

    • Send a POST request to the webhook URL
    • Verify successful registration and duplicate detection
    • Check database entries and audit logs