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¶
- Receives Input: The workflow is triggered by another workflow with a phone number and new onboarding status
- Validates User Exists: Queries the database to count how many users have the provided phone number
- Checks Count: If exactly one user is found, proceeds with the update; otherwise returns an error
- Gets User ID: Retrieves the specific user ID for the phone number
- Updates Status: Uses an upsert operation to update the user's onboarding status
- 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
youthEntrepreneursRealtable
Environment Variables¶
No environment variables are used in this workflow. All configuration is handled through n8n credentials.
Data Flow¶
Input¶
1 2 3 4 | |
Success Output¶
1 2 3 | |
Error Output¶
1 2 3 | |
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
onboardingStatusfield; 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
Related Workflows¶
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¶
-
Import the Workflow
- Copy the workflow JSON
- Import into your n8n instance
-
Configure PostgreSQL Credential
- Create a new PostgreSQL credential named "PostgresOnSupabase"
- Configure connection to your Supabase/PostgreSQL instance
- Ensure access to the
youthEntrepreneursRealtable
-
Database Requirements
- Ensure the
youthEntrepreneursRealtable exists with these columns:id(primary key)phoneNumber(string)onboardingStatus(string)
- Ensure the
-
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
-
Integration
- Call this workflow from other workflows using the "Execute Workflow" node
- Pass the required
phoneNumberandonboardingStatusparameters