Skip to content

Update User Data Tool Testing

This workflow provides a secure way to update user profile information in the youth entrepreneurs database. It validates that a user exists before making changes and provides clear feedback on whether the update succeeded or failed.

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 details while ensuring data integrity through validation checks.

How It Works

  1. Receive Update Request: The workflow accepts user data including phone number, first name, second name, and business information
  2. Validate User Exists: Checks the database to confirm exactly one user record exists with the provided phone number
  3. Branch Based on Validation:
    • If user exists: Proceeds with the update process
    • If user doesn't exist or multiple records found: Returns an error message
  4. Get User ID: For valid users, retrieves the internal user ID needed for the update
  5. Update Database: 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 accepts four input parameters: - phoneNumber - The user's phone number (used as identifier) - firstName - Updated first name - secondName - Updated second/last 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 provided phone number for validation
If If Determines if exactly one user record exists
Postgres Execute a SQL query1 Retrieves the user ID for the validated user
Postgres Insert or update rows in a table Updates the user record with new information
Set Edit Fields Returns error message when user validation fails
Set Edit Fields1 Returns success message when update completes

External Services & Credentials Required

  • PostgreSQL Database: Requires connection to a database containing the youthEntrepreneursReal table
    • Credential name: kdpTestEnv
    • Used for user validation and data updates

Environment Variables

No environment variables are explicitly used in this workflow. Database connection details are managed through n8n credentials.

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 prevent data corruption:

  • User Validation: Checks that exactly one user exists with the provided phone number
  • Graceful Failure: Returns a clear error message if the user cannot be found or if multiple records exist
  • No Partial Updates: The workflow only proceeds with updates if validation passes completely

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 what values were changed
  • Error message is generic and doesn't specify the exact validation failure

This workflow is designed to be called by other workflows that need to update user data. No specific related workflows are mentioned in the current configuration.

Setup Instructions

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

  2. Configure Database Credentials:

    • Create a PostgreSQL credential named kdpTestEnv
    • Ensure it has read/write access to the youthEntrepreneursReal table
  3. Verify Database Schema: Ensure your database has a table called youthEntrepreneursReal with these columns:

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

    • Create a test user record in your database
    • Call this workflow from another workflow with valid test data
    • Verify the update occurs and success message is returned
  5. Configure Calling Workflows: Set up other workflows to call this one using the "Execute Workflow" node with the required input parameters

  6. Set Permissions: Ensure the workflow caller policy allows execution from your intended source workflows