Skip to content

updateUserStatusTool - Francis

This workflow updates the onboarding status of youth entrepreneurs in a PostgreSQL database. It validates that a user exists by phone number, then updates their status if found, providing appropriate success or error messages.

Purpose

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

How It Works

  1. Receives Input: The workflow is triggered by another workflow with a phone number and new onboarding status
  2. Validates User Exists: Queries the database to count how many users have the provided phone number
  3. Checks Count: If exactly one user is found, proceeds with the update; otherwise returns an error
  4. Gets User ID: Retrieves the specific user ID for the phone number
  5. Updates Status: Uses an upsert operation to update the user's onboarding status
  6. Returns Success: Confirms the status update with a success message

Workflow 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. It expects two input parameters: - phoneNumber: The phone number of the user to update - onboardingStatus: The new status to set for the user

Nodes Used

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

External Services & Credentials Required

PostgreSQL Database

  • Credential Name: PostgresOnSupabase
  • Purpose: Access to the youth entrepreneurs database
  • Required Permissions: SELECT and UPDATE on the 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": "+254728309545",
  "onboardingStatus": "active"
}

Success Output

1
2
3
{
  "output": "User status for phone number +254728309545 has been updated"
}

Error Output

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 Response: If no user or multiple users are found, returns an error message instead of attempting the update
  • Database Constraints: Uses upsert operation to handle potential ID conflicts safely

Known Limitations

  • Only updates the onboardingStatus field; other user fields remain unchanged
  • Requires exact phone number match (case-sensitive)
  • No validation of the onboarding status value itself
  • Error message is generic and doesn't specify whether zero or multiple users were found

This workflow is designed to be called by other workflows that need to update user statuses. No specific related workflows are identified in the current context.

Setup Instructions

  1. Import the Workflow

    • Copy the workflow JSON
    • Import into your n8n instance
  2. Configure PostgreSQL Credential

    • Create a new PostgreSQL credential named "PostgresOnSupabase"
    • Configure connection to your Supabase/PostgreSQL instance
    • Ensure access to the youthEntrepreneursReal table
  3. Database Requirements

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

    • Use the pinned test data or create your own
    • Verify the phone number exists in your database
    • Execute and confirm the status update works
  5. Integration

    • Call this workflow from other workflows using the "Execute Workflow" node
    • Pass the required phoneNumber and onboardingStatus parameters