Skip to content

updateUserDataTool - Francis

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, second name, business ownership details, and communication channel preferences.

Purpose

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

How It Works

  1. Receives Input Parameters: The workflow accepts phone number, first name, second name, and business ownership information from another workflow
  2. Validates User Existence: Queries the database to check if exactly one user exists with the provided phone number
  3. Conditional Processing:
    • If user exists: Retrieves their ID and updates their profile information
    • If user doesn't exist or multiple records found: Returns an error message
  4. Updates Database: Performs an upsert operation to update the user's profile fields
  5. Returns Confirmation: Provides a success 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/multiple| 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 the following input parameters: - phoneNumber: 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
PostgreSQL Execute a SQL query Counts users with the provided phone number
If If Validates that exactly one user exists
PostgreSQL Execute a SQL query1 Retrieves the user ID for the phone number
PostgreSQL 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 Supabase PostgreSQL instance
    • Credential: PostgresOnSupabase (ID: Hw9XWerQ5RNHaVTk)
    • Access needed to youthEntrepreneursReal table

Environment Variables

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

Data Flow

Input:

1
2
3
4
5
6
{
  "phoneNumber": "+254793964781",
  "firstName": "Judy", 
  "secondName": "Kalondu",
  "businessOwned": "Second Hand Clothes (Mutumba)"
}

Output (Success):

1
2
3
{
  "output": "User record for phone number +254793964781 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 Path: If no user is found or multiple users exist, the workflow returns an error message instead of attempting to update
  • Database Constraints: Uses upsert operation with ID matching to prevent duplicate records

Known Limitations

  • Only updates specific fields (firstName, secondName, businessOwned, channel)
  • Requires exact phone number match for user identification
  • No validation of input data format or business rules
  • Error messages are generic and don't specify the exact issue (no user vs. multiple users)

This workflow is designed to be called by other workflows that need to update user profile information. No specific related workflows are identified in the current context.

Setup Instructions

  1. Import Workflow: Import the JSON into your n8n instance
  2. Configure Database Credential:
    • Create a PostgreSQL credential named "PostgresOnSupabase"
    • Configure connection to your Supabase PostgreSQL instance
    • Ensure access to the youthEntrepreneursReal table
  3. Database Schema: Ensure your database has the youthEntrepreneursReal table with these columns:
    • id (primary key)
    • phoneNumber (string)
    • firstName (string)
    • secondName (string)
    • businessOwned (string)
    • channel (string)
  4. Test the Workflow: Use the Execute Workflow node from another workflow with sample data
  5. Integration: Call this workflow from other workflows that need to update user profiles

Note: This workflow is currently inactive and may need to be activated before use.