Skip to content

updateUserStatusTool

A utility workflow that updates the onboarding status of youth entrepreneurs in the database based on their phone number. This workflow validates user existence before performing updates and provides clear feedback on the operation's success or failure.

Purpose

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

How It Works

  1. Input Validation: Receives a phone number and new onboarding status from another workflow
  2. User Verification: Queries the database to check if exactly one user exists with the provided phone number
  3. Conditional Processing:
    • If user exists: Retrieves their ID and updates their onboarding status
    • If user doesn't exist or multiple users found: Returns an error message
  4. Status Update: Updates the user's onboarding status in the database using their ID
  5. Response Generation: Returns a success message with the phone number or an error message

Mermaid Diagram

graph TD
    A[When Executed by Another Workflow] --> B[Execute a SQL query]
    B --> C[If]
    C -->|User Found| D[Execute a SQL query1]
    C -->|User Not Found| E[Edit Fields - Error]
    D --> F[Insert or update rows in a table]
    F --> G[Edit Fields1 - Success]

Trigger

Execute Workflow Trigger: This workflow is designed to be called by other workflows, not triggered directly. It accepts two input parameters: - phoneNumber: The phone number of the user to update - onboardingStatus: The new onboarding status to set

Nodes Used

Node Type Node Name Purpose
Execute Workflow Trigger When Executed by Another Workflow Receives input parameters from calling workflow
Postgres Execute a SQL query Counts users with the provided phone number
If If Validates that exactly one user exists
Postgres Execute a SQL query1 Retrieves the user ID for the phone number
Postgres Insert or update rows in a table Updates the user's onboarding status
Set Edit Fields Returns error message when user validation fails
Set Edit Fields1 Returns success message after successful update

External Services & Credentials Required

  • PostgreSQL Database: Requires access to the youthEntrepreneursReal table
    • Credential: kdpTables (PostgreSQL connection)
    • Permissions needed: SELECT and UPDATE on youthEntrepreneursReal table

Environment Variables

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

Data Flow

Input:

1
2
3
4
{
  "phoneNumber": "string",
  "onboardingStatus": "string"
}

Output (Success):

1
2
3
{
  "output": "User status for phone number [phoneNumber] has been updated"
}

Output (Error):

1
2
3
{
  "output": "Error updating user status"
}

Error Handling

The workflow includes validation to ensure data integrity:

  • User Validation: Checks that exactly one user exists with the provided phone number
  • Error Path: If validation fails (no user found or multiple users found), the workflow returns an error message instead of attempting the update
  • Database Errors: Any database connection or query errors will cause the workflow to fail with n8n's standard error handling

Known Limitations

  • The workflow only updates the onboardingStatus field; other user fields cannot be modified
  • Phone number matching is case-sensitive and requires exact matches
  • No validation is performed on the onboardingStatus value format
  • The workflow assumes phone numbers are unique in the database

This is a utility workflow designed to be called by other workflows that need to update user onboarding status. No specific related workflows are documented.

Setup Instructions

  1. Import the Workflow:

    • Copy the workflow JSON
    • Import into your n8n instance
  2. Configure Database Credentials:

    • Create a PostgreSQL credential named kdpTables
    • Configure connection to your database containing the youthEntrepreneursReal table
  3. Database Requirements:

    • Ensure the youthEntrepreneursReal table exists with these required columns:
      • id (number, primary key)
      • phoneNumber (string)
      • onboardingStatus (string)
  4. Test the Workflow:

    • Call from another workflow with valid test data
    • Verify the database update occurs correctly
    • Test error scenarios (non-existent phone numbers)
  5. Integration:

    • Use the "Execute Workflow" node in other workflows
    • Pass the required phoneNumber and onboardingStatus parameters
    • Handle the returned success/error messages appropriately