updateUserDataTool¶
This workflow provides a secure tool for updating user profile information in the youth entrepreneurs database. It validates user existence by phone number before allowing updates to personal details like names and business information.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
This workflow serves as a data management utility that allows other workflows to safely update user profile information. It ensures data integrity by validating that users exist before attempting updates, and provides clear feedback on the success or failure of update operations.
How It Works¶
- Input Validation: The workflow receives user data including phone number, first name, second name, and business information
- User Verification: Checks if exactly one user exists with the provided phone number in the database
- Conditional Processing: If the user exists, proceeds with the update; if not, returns an error message
- ID Retrieval: For valid users, fetches the internal user ID needed for the update operation
- Data Update: Updates the user's profile information using an upsert operation
- Success Confirmation: Returns a confirmation message with the updated phone number
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 accepts four input parameters:
- phoneNumber: The user's phone number (used as the lookup key)
- firstName: Updated first name
- secondName: Updated second name
- businessOwned: Updated business 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 given phone number |
| If | If | Validates that exactly one user exists |
| Postgres | Execute a SQL query1 | Retrieves the user ID for the update |
| 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 |
External Services & Credentials Required¶
- PostgreSQL Database: Requires connection to the
youthEntrepreneursRealtable- Credential: "Postgres account" (ID: EJPqF6MDH1ZwAzyv)
- Permissions needed: SELECT and UPDATE on the
youthEntrepreneursRealtable
Environment Variables¶
No environment variables are used in this workflow. All configuration is handled 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 built-in error handling:
- User Not Found: If no user or multiple users are found with the provided phone number, the workflow returns an error message instead of attempting an update
- Database Validation: The initial count query ensures data integrity before proceeding with updates
- Safe Updates: Uses upsert operations to prevent data corruption
Known Limitations¶
- Only updates three specific fields:
firstName,secondName, andbusinessOwned - Requires exact phone number match for user identification
- Does not validate the format or content of the updated data
- No audit trail of changes made to user records
Related Workflows¶
This is a utility workflow designed to be called by other workflows that need to update user information. Check for workflows that reference "updateUserDataTool" in their configurations.
Setup Instructions¶
-
Import the Workflow: Import the JSON into your n8n instance
-
Configure Database Credentials:
- Create a PostgreSQL credential named "Postgres account"
- Configure connection to your database containing the
youthEntrepreneursRealtable - Ensure the credential has SELECT and UPDATE permissions
-
Verify Database Schema: Ensure your
youthEntrepreneursRealtable includes these columns:id(primary key)phoneNumber(string)firstName(string)secondName(string)businessOwned(string)
-
Test the Workflow:
- Use the pinned test data or create your own test inputs
- Verify both success and error scenarios work correctly
-
Integration: Call this workflow from other workflows using the "Execute Workflow" node with the required input parameters
-
Activate: Enable the workflow once testing is complete