AppMage

Workflow

This endpoint group provides methods for managing and interacting with workflows, including creation, updates, deletion, retrieval, and execution. It also allows for dynamic interaction with running workflows and fetching associated metadata like tags and available tools.

Endpoints

POST /api/rpc (Method: WorkflowRpc.create)

  • Description: Create a new workflow

  • Request Body:

    {
      "method": "WorkflowRpc.create",
      "params": {
        "name": "My New Workflow",
        "description": "A detailed description of the workflow.",
        "nodes": [],
        "edges": [],
        "variables": {},
        "tags": ["automation", "marketing"]
      }
    }
  • Parameters:

    Name Type Required Description
    workflow Object Yes The workflow object to create. Excludes _id, createdAt, updatedAt, subscriptionId, and projectId.
  • Response:

    {
      "success": true,
      "data": {
        "_id": "65e8a7e0f2d8a0b1c2d3e4f5",
        "name": "My New Workflow",
        "description": "A detailed description of the workflow.",
        "nodes": [],
        "edges": [],
        "variables": {},
        "tags": ["automation", "marketing"],
        "subscriptionId": "sub_123",
        "contextId": null,
        "createdAt": "2023-01-01T00:00:00.000Z",
        "updatedAt": "2023-01-01T00:00:00.000Z"
      }
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "WorkflowRpc.create",
        "params": {
          "name": "My New Workflow",
          "description": "A detailed description of the workflow.",
          "nodes": [],
          "edges": [],
          "variables": {},
          "tags": ["automation", "marketing"]
        }
      }'

POST /api/rpc (Method: WorkflowRpc.update)

  • Description: Update an existing workflow

  • Request Body:

    {
      "method": "WorkflowRpc.update",
      "params": {
        "_id": "65e8a7e0f2d8a0b1c2d3e4f5",
        "name": "Updated Workflow Name",
        "description": "An updated description."
      }
    }
  • Parameters:

    Name Type Required Description
    workflow Object Yes The workflow object with the _id and fields to update. Excludes createdAt, updatedAt, subscriptionId, and projectId.
  • Response:

    {
      "success": true,
      "data": {
        "_id": "65e8a7e0f2d8a0b1c2d3e4f5",
        "name": "Updated Workflow Name",
        "description": "An updated description.",
        "nodes": [],
        "edges": [],
        "variables": {},
        "tags": ["automation", "marketing"],
        "subscriptionId": "sub_123",
        "contextId": null,
        "createdAt": "2023-01-01T00:00:00.000Z",
        "updatedAt": "2023-01-02T00:00:00.000Z"
      }
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "WorkflowRpc.update",
        "params": {
          "_id": "65e8a7e0f2d8a0b1c2d3e4f5",
          "name": "Updated Workflow Name",
          "description": "An updated description."
        }
      }'

POST /api/rpc (Method: WorkflowRpc.delete)

  • Description: Delete a workflow

  • Request Body:

    {
      "method": "WorkflowRpc.delete",
      "params": {
        "_id": "65e8a7e0f2d8a0b1c2d3e4f5"
      }
    }
  • Parameters:

    Name Type Required Description
    _id String Yes The unique identifier of the workflow to delete.
  • Response:

    {
      "success": true
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "WorkflowRpc.delete",
        "params": {
          "_id": "65e8a7e0f2d8a0b1c2d3e4f5"
        }
      }'

POST /api/rpc (Method: WorkflowRpc.findById)

  • Description: Get a workflow by ID

  • Request Body:

    {
      "method": "WorkflowRpc.findById",
      "params": {
        "id": "65e8a7e0f2d8a0b1c2d3e4f5"
      }
    }
  • Parameters:

    Name Type Required Description
    id String Yes The unique identifier of the workflow to retrieve.
  • Response:

    {
      "success": true,
      "data": {
        "_id": "65e8a7e0f2d8a0b1c2d3e4f5",
        "name": "My New Workflow",
        "description": "A detailed description of the workflow.",
        "nodes": [],
        "edges": [],
        "variables": {},
        "tags": ["automation", "marketing"],
        "subscriptionId": "sub_123",
        "contextId": null,
        "createdAt": "2023-01-01T00:00:00.000Z",
        "updatedAt": "2023-01-01T00:00:00.000Z"
      }
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "WorkflowRpc.findById",
        "params": {
          "id": "65e8a7e0f2d8a0b1c2d3e4f5"
        }
      }'

POST /api/rpc (Method: WorkflowRpc.getData)

  • Description: Get a list of workflows

  • Request Body:

    {
      "method": "WorkflowRpc.getData",
      "params": {
        "filter": {
          "name": { "$regex": "marketing", "$options": "i" }
        },
        "sort": {
          "createdAt": -1
        },
        "page": 1,
        "pageSize": 10
      }
    }
  • Parameters:

    Name Type Required Description
    filter Object No An object to filter the workflows. Supports MongoDB query operators.
    sort Object No An object to define the sort order (e.g., { createdAt: -1 }).
    page Number No The page number for pagination (defaults to 1).
    pageSize Number No The number of items per page (defaults to 25).
  • Response:

    {
      "success": true,
      "data": {
        "data": [
          {
            "_id": "65e8a7e0f2d8a0b1c2d3e4f5",
            "name": "Marketing Campaign Workflow",
            "description": "Automates social media posts.",
            "tags": ["marketing"]
          }
        ],
        "totalCount": 1
      }
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "WorkflowRpc.getData",
        "params": {
          "filter": {
            "tags": "marketing"
          },
          "page": 1,
          "pageSize": 10
        }
      }'

POST /api/rpc (Method: WorkflowRpc.executeWorkflow)

  • Description: Execute a workflow

  • Request Body:

    {
      "method": "WorkflowRpc.executeWorkflow",
      "params": {
        "workflowIdentifier": "MyWorkflowName",
        "workflowArgs": {
          "leadId": "12345",
          "campaign": "Spring2024"
        },
        "context": {
          "correlationId": "abc-123"
        }
      }
    }
  • Parameters:

    Name Type Required Description
    workflowIdentifier String Yes The name or _id of the workflow to execute.
    workflowArgs Object No Optional arguments to pass to the workflow.
    context Object No Optional context information for the workflow execution.
  • Response:

    {
      "success": true,
      "data": {
        "result": {
          "status": "completed",
          "output": {
            "message": "Workflow executed successfully."
          }
        }
      }
    }

    or

    {
      "success": false,
      "data": {
        "error": "Workflow not found."
      }
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "WorkflowRpc.executeWorkflow",
        "params": {
          "workflowIdentifier": "MyWorkflowName",
          "workflowArgs": {
            "data": "some input"
          }
        }
      }'

POST /api/rpc (Method: WorkflowRpc.sendEventToWorkflow)

  • Description: Send an event to a running workflow

  • Request Body:

    {
      "method": "WorkflowRpc.sendEventToWorkflow",
      "params": {
        "workflowName": "MyLongRunningWorkflow",
        "eventName": "UserApproved",
        "eventData": {
          "userId": "user_abc",
          "approvalDate": "2024-03-15T10:00:00Z"
        },
        "context": {
          "id": "workflowInstanceId_xyz"
        }
      }
    }
  • Parameters:

    Name Type Required Description
    workflowName String Yes The name of the workflow to send the event to.
    eventName String Yes The name of the event being sent.
    eventData Object Yes The data associated with the event.
    context Object No Optional context for the event, potentially including a workflow instance id.
  • Response:

    {
      "success": true
    }

    or

    {
      "success": false,
      "data": {
        "error": "Workflow instance not found or event handler failed."
      }
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "WorkflowRpc.sendEventToWorkflow",
        "params": {
          "workflowName": "OrderProcessingWorkflow",
          "eventName": "PaymentReceived",
          "eventData": {
            "orderId": "ORD-456",
            "amount": 100
          }
        }
      }'

POST /api/rpc (Method: WorkflowRpc.getAvailableTools)

  • Description: Gets the available workflow tools

  • Request Body:

    {
      "method": "WorkflowRpc.getAvailableTools",
      "params": {}
    }
  • Parameters:

    Name Type Required Description
    (None) This method takes no parameters.
  • Response:

    {
      "success": true,
      "data": [
        {
          "name": "SendEmailTool",
          "description": "Sends an email.",
          "schema": {
            "type": "object",
            "properties": {
              "to": { "type": "string" },
              "subject": { "type": "string" },
              "body": { "type": "string" }
            }
          }
        },
        {
          "name": "CreateLeadTool",
          "description": "Creates a new CRM lead.",
          "schema": {
            "type": "object",
            "properties": {
              "firstName": { "type": "string" },
              "lastName": { "type": "string" },
              "email": { "type": "string" }
            }
          }
        }
      ]
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "WorkflowRpc.getAvailableTools",
        "params": {}
      }'

POST /api/rpc (Method: WorkflowRpc.generateDynamicLeads)

  • Description: Gets the available workflow tools

  • Request Body:

    {
      "method": "WorkflowRpc.generateDynamicLeads",
      "params": {
        "toolClassName": "LeadGenerationTool",
        "properties": {
          "industry": "Tech",
          "region": "North America"
        }
      }
    }
  • Parameters:

    Name Type Required Description
    toolClassName String Yes The class name of the tool to use for lead generation.
    properties Any Yes Properties specific to the tool for generating leads.
  • Response:

    {
      "success": true,
      "data": [
        {
          "name": "John Doe",
          "email": "[email protected]",
          "company": "Tech Innovations"
        },
        {
          "name": "Jane Smith",
          "email": "[email protected]",
          "company": "Software Solutions"
        }
      ]
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "WorkflowRpc.generateDynamicLeads",
        "params": {
          "toolClassName": "SomeLeadGenTool",
          "properties": {
            "criteria": "high-growth startups"
          }
        }
      }'

POST /api/rpc (Method: WorkflowRpc.getWorkflowTags)

  • Description: Gets all unique tags used across all workflows in the current context.

  • Request Body:

    {
      "method": "WorkflowRpc.getWorkflowTags",
      "params": {}
    }
  • Parameters:

    Name Type Required Description
    (None) This method takes no parameters.
  • Response:

    {
      "success": true,
      "data": [
        { "value": "automation", "label": "automation" },
        { "value": "marketing", "label": "marketing" },
        { "value": "sales", "label": "sales" }
      ]
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "WorkflowRpc.getWorkflowTags",
        "params": {}
      }'

POST /api/rpc (Method: WorkflowRpc.getFieldValues)

  • Description: Gets reference field values for DataForm, such as a list of workflows or AI agents.

  • Request Body:

    {
      "method": "WorkflowRpc.getFieldValues",
      "params": {
        "fieldName": "relatedWorkflow",
        "reference": {
          "collection": "workflows",
          "valueField": "_id",
          "displayField": "name",
          "filter": {
            "tags": "automation"
          }
        }
      }
    }
  • Parameters:

    Name Type Required Description
    fieldName String Yes The name of the field requesting reference values.
    reference Object Yes An object defining the reference details.
    reference.collection String Yes The collection to fetch values from (e.g., workflows, agentConfigs).
    reference.valueField String Yes The field to use as the value for each option.
    reference.displayField String Yes The field to use as the display label for each option.
    reference.filter Object No Optional filter to apply when fetching reference values.
    reference.sort Object No Optional sort to apply when fetching reference values.
  • Response:

    {
      "success": true,
      "data": [
        {
          "value": "65e8a7e0f2d8a0b1c2d3e4f5",
          "label": "My Automation Workflow"
        },
        {
          "value": "65e8a7e0f2d8a0b1c2d3e4f6",
          "label": "Daily Report Workflow"
        }
      ]
    }
  • Example (cURL):

    curl -X POST https://api.example.com/api/rpc \
      -H "Content-Type: application/json" \
      -H "X-API-Key: YOUR_API_KEY" \
      -d '{
        "method": "WorkflowRpc.getFieldValues",
        "params": {
          "fieldName": "selectedAgent",
          "reference": {
            "collection": "agentConfigs",
            "valueField": "_id",
            "displayField": "name",
            "filter": {
              "status": "active"
            }
          }
        }
      }'