updateUserDataTool - Francis¶
A utility workflow that updates user profile information in the youth entrepreneurs database. This workflow validates user existence by phone number and updates their first name, second name, business ownership details, and communication channel preferences.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
- Receives Input Parameters: The workflow accepts phone number, first name, second name, and business ownership information 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 profile information
- If user doesn't exist or multiple records found: Returns an error message
- Updates User Data: Performs an upsert operation to update the user's profile fields
- Returns Confirmation: Provides success or error feedback based on the operation result
Mermaid 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 the following input parameters:
- phoneNumber: User's phone number for identification
- firstName: Updated first name
- secondName: Updated second name
- businessOwned: Updated business ownership information
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 provided phone number |
| If | If | Validates that exactly one user exists |
| Postgres | Execute a SQL query1 | Retrieves the user ID for the phone number |
| Postgres | Insert or update rows in a table | Updates user profile information |
| 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 Supabase PostgreSQL instance
- Credential:
PostgresOnSupabase(ID: Hw9XWerQ5RNHaVTk) - Access needed to
youthEntrepreneursRealtable
- Credential:
Environment Variables¶
No environment variables are directly referenced in this workflow. Database connection details are managed through n8n credentials.
Data Flow¶
Input:
1 2 3 4 5 6 | |
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
- Conditional Branching: Routes to error handling if user validation fails
- Error Messages: Returns descriptive error message when update cannot be performed
Error scenarios handled: - Phone number not found in database - Multiple users with same phone number - Database connection issues
Known Limitations¶
- Only updates specific fields (firstName, secondName, businessOwned, channel)
- Requires exact phone number match for user identification
- No validation of input data format or business rules
- Channel field is referenced but not provided in input parameters
Related Workflows¶
This is a utility workflow designed to be called by other workflows that need to update user profile information.
Setup Instructions¶
-
Import the Workflow: Import the JSON into your n8n instance
-
Configure Database Credentials:
- Create a PostgreSQL credential named "PostgresOnSupabase"
- Configure connection to your Supabase PostgreSQL instance
- Ensure access to the
youthEntrepreneursRealtable
-
Database Schema Requirements: The workflow expects a table
youthEntrepreneursRealwith these columns:id(number, primary key)phoneNumber(string)firstName(string)secondName(string)businessOwned(string)channel(string)
-
Test the Workflow:
- Use the pinned test data or call from another workflow
- Verify database connectivity and permissions
- Test both success and error scenarios
-
Integration: Call this workflow from other workflows using the Execute Workflow node, passing the required parameters