updateUserDataTool¶
This workflow provides a secure way to update user profile information in the youth entrepreneurs database. It 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.
This workflow serves as a data management tool for updating user profiles in what appears to be a youth entrepreneurship program. It allows other workflows or systems to safely update user information like names and business ownership details while ensuring data integrity through validation checks.
How It Works¶
- Receive Update Request: The workflow receives user data including phone number, first name, second name, and business ownership information
- Validate User Exists: Queries the database to check if a user with the provided phone number exists
- Branch Based on Validation:
- If exactly one user is found, proceed with the update
- If no user or multiple users are found, return an error message
- Retrieve User ID: For valid users, fetch their database ID using the phone number
- Update User Record: Perform an upsert operation to update the user's profile information
- Return Success Message: Confirm 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 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, not triggered directly. It accepts four input parameters:
- phoneNumber: The user's phone number (used as identifier)
- 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's database ID |
| 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 message after update |
External Services & Credentials Required¶
PostgreSQL Database:
- Credential Name: "Postgres account"
- Access to youthEntrepreneursReal table with read/write permissions
- Required for user validation and profile updates
Environment Variables¶
No environment variables are used in this workflow. All configuration is handled through n8n credentials.
Data Flow¶
Input Parameters:
- phoneNumber (string): User identifier
- firstName (string): New first name
- secondName (string): New second name
- businessOwned (string): New business ownership status
Output:
- Success: "User record for phone number {phoneNumber} has been updated"
- Error: "Error updating user data"
Database Operations:
- Reads from youthEntrepreneursReal table to validate user existence
- Updates firstName, secondName, and businessOwned fields for the matched user
Error Handling¶
The workflow includes validation to prevent data corruption:
- User Existence Check: Verifies exactly one user exists with the provided phone number
- Conditional Branching: Routes to error handling if validation fails
- Clear Error Messages: Returns descriptive error message when updates cannot be performed
- Error Workflow: Configured to use error workflow "cuHEGQjAfvuGwIOD" for unhandled exceptions
Known Limitations¶
- Only updates three specific fields: firstName, secondName, and businessOwned
- Requires exact phone number match for user identification
- Does not validate the format or content of the updated data
- Cannot create new users, only update existing ones
Related Workflows¶
This workflow is designed to be called by other workflows in the system. The error workflow "cuHEGQjAfvuGwIOD" handles any unhandled exceptions.
Setup Instructions¶
-
Import the Workflow: Import the JSON into your n8n instance
-
Configure Database Credentials:
- Create a PostgreSQL credential named "Postgres account"
- Ensure connection to database containing
youthEntrepreneursRealtable - Verify the credential has SELECT and UPDATE permissions
-
Verify Database Schema: Ensure the
youthEntrepreneursRealtable includes:id(primary key)phoneNumber(string)firstName(string)secondName(string)businessOwned(string)
-
Test the Workflow:
- Execute with valid test data
- Verify both success and error scenarios
- Check database updates are applied correctly
-
Integration: Call this workflow from other workflows using the Execute Workflow node with the required input parameters
The workflow is configured to only accept calls from workflows owned by the same user for security purposes.