Update User Status Tool¶
This workflow provides a secure, auditable way to update user onboarding status in the youth entrepreneurs database. It validates user existence, updates their status, logs the change for audit purposes, and returns appropriate success or error messages.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
This workflow serves as a utility tool for updating user onboarding status within what appears to be a youth entrepreneurship program. It ensures data integrity by validating user existence before making changes and maintains an audit trail of all status updates.
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 check if exactly one user exists with the provided phone number
- Branch Based on Validation:
- If user exists: Proceeds with the update process
- If user doesn't exist or multiple users found: Returns an error message
- Get User ID: Retrieves the specific user ID for the phone number
- Log Status Change: Records the status change in an audit log before making the update
- Update Status: Updates the user's onboarding status in the main table
- Return Success: Confirms the update was completed successfully
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[Log Status Change]
D --> G[Insert or update rows in a table]
G --> H[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 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 |
| Postgres | Execute a SQL query | Counts users with the given phone number for validation |
| If | If | Determines if exactly one user exists with the phone number |
| Postgres | Execute a SQL query1 | Retrieves the user ID for the validated phone number |
| Postgres | Log Status Change | Records the status change in the audit log |
| Postgres | Insert or update rows in a table | Updates the user's onboarding status |
| Set | Edit Fields | Formats error message when user validation fails |
| Set | Edit Fields1 | Formats success message when update completes |
External Services & Credentials Required¶
PostgreSQL Database:
- Credential ID: EJPqF6MDH1ZwAzyv
- Credential Name: "Postgres account"
- Required for all database operations including user validation, status updates, and audit logging
Environment Variables¶
No environment variables are explicitly used in this workflow. All configuration is handled through the PostgreSQL credentials.
Data Flow¶
Input:
- phoneNumber (string): Phone number identifying the user to update
- onboardingStatus (string): New onboarding status to set
Output:
- Success: "User status for phone number {phoneNumber} has been updated"
- Error: "Error updating user status"
Database Tables Used:
- youthEntrepreneursReal: Main user table containing user profiles and onboarding status
- userStatusLog: Audit log table tracking status changes
Error Handling¶
The workflow includes validation to ensure data integrity:
- User Validation: Checks that exactly one user exists with the provided phone number
- Error Path: If validation fails (no user found or multiple users), the workflow returns an error message instead of attempting updates
- Error Workflow: The workflow is configured with error workflow ID
cuHEGQjAfvuGwIODfor handling unexpected failures
Known Limitations¶
- The workflow only updates the
onboardingStatusfield and cannot modify other user attributes - Phone number matching is case-sensitive and requires exact matches
- No validation is performed on the new status value itself
- The workflow assumes phone numbers are unique identifiers in the system
Related Workflows¶
This workflow is designed to be called by other workflows but no specific related workflows are identified in the current configuration.
Setup Instructions¶
-
Import Workflow: Import the workflow JSON into your n8n instance
-
Configure PostgreSQL Credentials:
- Create a PostgreSQL credential named "Postgres account"
- Ensure it has read/write access to the
youthEntrepreneursRealanduserStatusLogtables
-
Database Schema Requirements:
- Ensure the
youthEntrepreneursRealtable exists with columns:id,phoneNumber,onboardingStatus - Ensure the
userStatusLogtable exists with columns:phoneNumber,previousStatus,newStatus
- Ensure the
-
Set Caller Policy: The workflow is configured to only accept calls from workflows owned by the same user (
workflowsFromSameOwner) -
Configure Error Handling: Optionally set up the error workflow (ID:
cuHEGQjAfvuGwIOD) for handling unexpected failures -
Test the Workflow: Call it from another workflow with valid test data to ensure proper functionality
-
Activate: Activate the workflow to make it available for other workflows to call