Skip to content

V4 - updateUserDataTool

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, last name, and business ownership status.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

How It Works

  1. Receive Input Parameters: The workflow accepts four parameters: phone number, first name, second name, and business ownership status
  2. Validate User Exists: Queries the database to check if exactly one user exists with the provided phone number
  3. Branch Based on Validation:
    • If user exists (count = 1): Proceeds to update the user record
    • If user doesn't exist or multiple records found: Returns an error message
  4. Get User ID: Retrieves the internal ID for the user based on their phone number
  5. Update User Record: Performs an upsert operation to update the user's profile information
  6. Return Success Message: 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[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 four input parameters: - phoneNumber: The user's phone number for identification - firstName: New first name to update - secondName: New last name to update
- businessOwned: Business ownership status to update

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 internal 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 confirmation message

External Services & Credentials Required

  • PostgreSQL Database: Requires connection to a Postgres database containing the youthEntrepreneursReal table
  • Database Credentials: PostgreSQL connection credentials with read/write access to the user table

Environment Variables

No specific environment variables are referenced in this workflow. Database connection details are managed through n8n's credential system.

Data Flow

Input

1
2
3
4
5
6
{
  "phoneNumber": "string",
  "firstName": "string", 
  "secondName": "string",
  "businessOwned": "string"
}

Output (Success)

1
2
3
{
  "output": "User record for phone number [phoneNumber] has been updated"
}

Output (Error)

1
2
3
{
  "output": "Error updating user data"
}

Error Handling

The workflow includes validation to ensure data integrity:

  • User Validation: Checks that exactly one user exists with the provided phone number
  • Error Response: Returns a generic error message if the user is not found or if multiple users exist with the same phone number
  • Error Workflow: The workflow settings reference an error workflow (cuHEGQjAfvuGwIOD) that will be triggered if the workflow fails

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 input data
  • Returns a generic error message that doesn't specify the exact issue (user not found vs. multiple users)
  • Error handling workflow: cuHEGQjAfvuGwIOD

Setup Instructions

  1. Import the Workflow: Import the JSON into your n8n instance

  2. Configure Database Connection:

    • Set up PostgreSQL credentials in n8n
    • Ensure connection to database with youthEntrepreneursReal table
    • Verify the table has columns: id, phoneNumber, firstName, secondName, businessOwned
  3. Set Permissions:

    • Configure caller policy to allow execution from other workflows
    • Ensure the database user has SELECT and UPDATE permissions on the target table
  4. Test the Workflow:

    • Create a test workflow that calls this one with sample data
    • Verify both success and error scenarios work correctly
  5. Error Workflow Setup:

    • Ensure the referenced error workflow (cuHEGQjAfvuGwIOD) exists and is properly configured

The workflow is ready to use once the database connection is established and the calling workflow provides the required input parameters.