Skip to main content

Overview

The Manage Workflows endpoint provides operations for saving and loading workflow configurations. Each user can have one active workflow stored in the database.

Endpoint

POST https://<your-project>.supabase.co/functions/v1/manage-workflows

Authentication

Requires a valid Supabase JWT token:
Authorization: Bearer <your-jwt-token>

Operations

Save Workflow

Saves or updates the user’s workflow. Creates a new workflow if none exists, otherwise updates the existing one.

Request Body

action
string
required
Must be "save" for save operations
workflowData
object
required
The complete workflow structure including elements and connections
workflowName
string
Optional workflow name (currently defaults to “My Workflow”)

Example Request

curl -X POST https://your-project.supabase.co/functions/v1/manage-workflows \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -d '{
    "action": "save",
    "workflowData": {
      "elements": [
        {
          "id": "element-1",
          "type": "agent",
          "agentId": "1",
          "position": { "x": 200, "y": 300 },
          "data": {
            "name": "Text Generator",
            "description": "Generates text based on prompts",
            "color": "#f0f9ff"
          }
        }
      ],
      "connections": []
    }
  }'

Success Response (200)

message
string
Success message
workflow
object
The saved workflow record including database metadata

Example Response

{
  "message": "Workflow saved successfully",
  "workflow": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "user_id": "123e4567-e89b-12d3-a456-426614174000",
    "name": "My Workflow",
    "data": {
      "elements": [...],
      "connections": [...]
    },
    "created_at": "2024-03-15T10:30:00.000Z",
    "updated_at": "2024-03-15T10:30:00.000Z"
  }
}

Load Workflow

Retrieves the user’s saved workflow from the database.

Request Body

action
string
required
Must be "load" for load operations

Example Request

curl -X POST https://your-project.supabase.co/functions/v1/manage-workflows \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -d '{
    "action": "load"
  }'

Success Response (200)

success
boolean
Always true for successful requests
workflow
object | null
The user’s workflow record, or null if no workflow exists

Example Response

{
  "success": true,
  "workflow": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "user_id": "123e4567-e89b-12d3-a456-426614174000",
    "name": "My Workflow",
    "data": {
      "elements": [...],
      "connections": [...]
    },
    "created_at": "2024-03-15T10:30:00.000Z",
    "updated_at": "2024-03-15T10:30:00.000Z"
  }
}

Error Responses

400 Bad Request

{
  "error": "Workflow data is required"
}
or
{
  "error": "Invalid action"
}

401 Unauthorized

{
  "error": "Authorization header is required"
}
or
{
  "error": "Not authenticated"
}

500 Internal Server Error

{
  "error": "Database error message"
}

Database Schema

Workflows are stored in the user_workflows table:
CREATE TABLE user_workflows (
  id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
  user_id UUID NOT NULL REFERENCES auth.users(id),
  name TEXT NOT NULL DEFAULT 'My Workflow',
  data JSONB NOT NULL,
  created_at TIMESTAMPTZ DEFAULT now(),
  updated_at TIMESTAMPTZ DEFAULT now(),
  UNIQUE(user_id)
);
Each user can have only one workflow (enforced by UNIQUE(user_id) constraint). Saving a new workflow updates the existing one.

Usage Pattern

Typical workflow management flow:
  1. On App Load: Call with action: "load" to retrieve saved workflow
  2. Auto-Save: Periodically call with action: "save" during editing
  3. Manual Save: Call with action: "save" when user clicks save button

Row Level Security

The user_workflows table uses RLS to ensure:
  • Users can only read their own workflows
  • Users can only update/delete their own workflows
  • Workflows are automatically filtered by user_id

See Also

Build docs developers (and LLMs) love