Skip to content

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

  1. Input Validation: The workflow receives user data including phone number, first name, second name, and business information
  2. User Verification: Checks if exactly one user exists with the provided phone number in the database
  3. Conditional Processing: If the user exists, proceeds with the update; if not, returns an error message
  4. ID Retrieval: For valid users, fetches the internal user ID needed for the update operation
  5. Data Update: Updates the user's profile information using an upsert operation
  6. 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 youthEntrepreneursReal table
    • Credential: "Postgres account" (ID: EJPqF6MDH1ZwAzyv)
    • Permissions needed: SELECT and UPDATE on the youthEntrepreneursReal table

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
{
  "phoneNumber": "+254793964781",
  "firstName": "Judy", 
  "secondName": "Kalondu",
  "businessOwned": "Second Hand Clothes (Mutumba)"
}

Success Output:

1
2
3
{
  "output": "User record for phone number +254793964781 has been updated"
}

Error Output:

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

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, and businessOwned
  • 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

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

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

  2. Configure Database Credentials:

    • Create a PostgreSQL credential named "Postgres account"
    • Configure connection to your database containing the youthEntrepreneursReal table
    • Ensure the credential has SELECT and UPDATE permissions
  3. Verify Database Schema: Ensure your youthEntrepreneursReal table includes these columns:

    • id (primary key)
    • phoneNumber (string)
    • firstName (string)
    • secondName (string)
    • businessOwned (string)
  4. Test the Workflow:

    • Use the pinned test data or create your own test inputs
    • Verify both success and error scenarios work correctly
  5. Integration: Call this workflow from other workflows using the "Execute Workflow" node with the required input parameters

  6. Activate: Enable the workflow once testing is complete