Skip to content

updateUserStatusTool - Francis

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. Receives Input: The workflow accepts a phone number and new onboarding status from another workflow
  2. Validates User Existence: 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. Database Update: Uses an upsert operation to update the user's onboarding status
  5. Returns Confirmation: Provides a success message confirming the status update

Workflow Diagram

graph TD
    A[When Executed by Another Workflow] --> B[Execute a SQL query]
    B --> C[If]
    C -->|User exists| 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 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
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 update
PostgreSQL Insert or update rows in a table Updates the user's onboarding status
Set Edit Fields Returns error message for invalid users
Set Edit Fields1 Returns success confirmation message

External Services & Credentials Required

  • PostgreSQL Database: Requires connection to a Supabase PostgreSQL instance
    • Credential name: PostgresOnSupabase
    • Access needed: Read and write permissions on the youthEntrepreneursReal table

Environment Variables

No environment variables are directly used in this workflow. Database connection details are managed 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 if exactly one user exists with the provided phone number
  • Error Path: If no user is found or multiple users exist, the workflow returns an error message instead of attempting an update
  • Database Constraints: Uses upsert operation to handle potential ID conflicts gracefully

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 format
  • Error messages are generic and don't specify whether zero or multiple users were found

This is a utility workflow designed to be called by other workflows that need to update user onboarding status. 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 Database Credentials:

    • Create a PostgreSQL credential named PostgresOnSupabase
    • Configure connection to your Supabase database
    • Ensure access to the youthEntrepreneursReal table
  3. Database Schema Requirements:

    • Table: youthEntrepreneursReal
    • Required columns: id, phoneNumber, onboardingStatus
    • The id column should be the primary key
  4. Test the Workflow:

    • Use the pinned test data or create your own
    • Verify database connectivity
    • Test both success and error scenarios
  5. Integration:

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