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¶
- Receives Input: The workflow accepts a phone number and new onboarding status from another workflow
- Validates User Existence: Queries the database to check if exactly one user exists with the provided phone number
- 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
- Database Update: Uses an upsert operation to update the user's onboarding status
- 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
youthEntrepreneursRealtable
- Credential name:
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 | |
Success Output:
1 2 3 | |
Error Output:
1 2 3 | |
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
onboardingStatusfield; 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
Related Workflows¶
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¶
-
Import the Workflow:
- Copy the workflow JSON
- Import into your n8n instance
-
Configure Database Credentials:
- Create a PostgreSQL credential named
PostgresOnSupabase - Configure connection to your Supabase database
- Ensure access to the
youthEntrepreneursRealtable
- Create a PostgreSQL credential named
-
Database Schema Requirements:
- Table:
youthEntrepreneursReal - Required columns:
id,phoneNumber,onboardingStatus - The
idcolumn should be the primary key
- Table:
-
Test the Workflow:
- Use the pinned test data or create your own
- Verify database connectivity
- Test both success and error scenarios
-
Integration:
- Call this workflow from other workflows using the "Execute Workflow" node
- Pass the required
phoneNumberandonboardingStatusparameters