Update User Status Tool¶
This workflow provides a utility service for updating the onboarding status of youth entrepreneurs in the database. It validates user existence by phone number and safely updates their status, returning appropriate success or error messages.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
This workflow serves as a reusable tool for managing user onboarding states within what appears to be a youth entrepreneurship program. It ensures data integrity by validating user existence before making updates and provides clear feedback on operation success or failure.
How It Works¶
- Receive Input: The workflow accepts a phone number and new onboarding status from another workflow
- Validate User Exists: Queries the database to count how many users have the provided phone number
- Check Count: Verifies exactly one user exists with that phone number
- Handle Success Path: If user exists, retrieves their ID and updates their onboarding status
- Handle Error Path: If user doesn't exist or multiple users found, returns an error message
- Return Result: Provides confirmation message or error details back to the calling workflow
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, not triggered directly. It expects two input parameters:
- phoneNumber: The phone number to identify the user
- 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 provided 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 validation fails |
| Set | Edit Fields1 | Returns success message when update completes |
External Services & Credentials Required¶
- PostgreSQL Database: Requires connection to a Supabase PostgreSQL instance
- Credential name:
PostgresOnSupabase - Used for: Reading and updating 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:
- phoneNumber (string): Phone number to identify the user (e.g., "+254728309545")
- onboardingStatus (string): New status to set (e.g., "active")
Output:
- Success: "User status for phone number {phoneNumber} has been updated"
- Error: "Error updating user status"
Database Operations:
- Reads from youthEntrepreneursReal table to validate user existence
- Updates the onboardingStatus field for the identified user
Error Handling¶
The workflow includes built-in error handling:
- User Validation: If the phone number doesn't match exactly one user (0 or multiple matches), the workflow returns an error message instead of attempting the update
- Safe Updates: Uses the user's ID for updates rather than phone number to ensure precision
- Clear Feedback: Provides specific success or error messages to help calling workflows understand the result
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
- Assumes phone numbers are unique in the database
Related Workflows¶
No related workflows specified in the provided context.
Setup Instructions¶
-
Import Workflow: Import the workflow JSON into your n8n instance
-
Configure Database Credentials:
- Create a PostgreSQL credential named
PostgresOnSupabase - Configure connection to your Supabase PostgreSQL database
- Ensure the credential has read/write access to the
youthEntrepreneursRealtable
- Create a PostgreSQL credential named
-
Verify Database Schema: Ensure your database has a
youthEntrepreneursRealtable with these required columns:id(primary key)phoneNumber(string)onboardingStatus(string)
-
Test the Workflow:
- Use the pinned test data or call from another workflow
- Verify both success and error paths work correctly
- Check that database updates are applied properly
-
Integration: Call this workflow from other workflows using the Execute Workflow node, passing the required
phoneNumberandonboardingStatusparameters