{
  "openapi": "3.0.0",
  "info": {
    "title": "DataAgents Workflow Runs API",
    "version": "1",
    "description": "Trigger a workflow for an individual record or a batch and search execution history."
  },
  "servers": [
    {
      "url": "https://backend.snapaddy.com/job-management"
    }
  ],
  "paths": {
    "/jobs/workflow": {
      "post": {
        "operationId": "WorkflowJobController_createWorkflowJob",
        "summary": "Run a workflow by trigger name",
        "description": "Create a new workflow job for the current organization",
        "parameters": [],
        "responses": {
          "201": {
            "description": "The workflow job was queued. Read id from the response to track this run.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkflowJobResponseDto"
                }
              }
            }
          },
          "403": {
            "description": "Your account lacks access to this operation."
          },
          "404": {
            "description": "No workflow found for the given trigger",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorArrayException"
                }
              }
            }
          },
          "409": {
            "description": "No workflow job was created because the email inbox trigger was not valid."
          },
          "422": {
            "description": "The requested workflow is not enabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorArrayException"
                }
              }
            }
          }
        },
        "security": [
          {
            "x-api-key": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WorkflowJobPostRequestDto"
              },
              "example": {
                "trigger": "web-lead",
                "data": {
                  "firstName": "Alex",
                  "lastName": "Morgan",
                  "email": "alex@example.com"
                }
              }
            }
          }
        }
      }
    },
    "/jobs/workflow/bulk": {
      "post": {
        "operationId": "WorkflowJobController_createWorkflowJobsByTrigger",
        "summary": "Submit a group of workflow runs",
        "description": "Queue one workflow job per entry for the named trigger. The creation response has no body.",
        "parameters": [],
        "responses": {
          "201": {
            "description": "The batch was accepted. The response has an empty body."
          },
          "403": {
            "description": "Your account lacks access to this operation."
          },
          "404": {
            "description": "No workflow found for the given trigger",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorArrayException"
                }
              }
            }
          },
          "409": {
            "description": "No workflow jobs were created because an inbox connection is required for the email trigger."
          },
          "422": {
            "description": "The requested workflow is not enabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorArrayException"
                }
              }
            }
          }
        },
        "security": [
          {
            "x-api-key": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PostBulkWorkflowJobByTriggerRequestDto"
              },
              "example": {
                "trigger": "web-lead",
                "groupName": "Event leads",
                "data": [
                  {
                    "firstName": "Alex",
                    "lastName": "Morgan",
                    "email": "alex@example.com"
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/v2/jobs/workflow/search": {
      "post": {
        "operationId": "WorkflowJobV2Controller_searchWorkflowJobs",
        "summary": "Search workflow executions",
        "description": "Find workflow runs in your organization. Requires the DataAgents Manager role. Filter by workflow, job, group or creation time and page through results.",
        "parameters": [],
        "responses": {
          "201": {
            "description": "The results array contains the workflow runs matching your search.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PostWorkflowJobsSearchV2ResponseDto"
                }
              }
            }
          },
          "403": {
            "description": "Your account lacks access to this operation."
          }
        },
        "security": [
          {
            "x-api-key": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PostWorkflowJobsSearchV2RequestDto"
              },
              "example": {
                "limit": 10,
                "offset": 0,
                "sortDirection": "DESC"
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "WorkflowJobResponseDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Job ID for this run. Pass it to GET /jobs/{id} in Job Management to check progress."
          },
          "type": {
            "type": "string",
            "description": "Type of the job.",
            "enum": [
              "data_enrichment",
              "vr_download",
              "workflow",
              "digital_card",
              "crm_inventory_data_download"
            ]
          },
          "state": {
            "type": "string",
            "description": "Current lifecycle state of the job.",
            "enum": [
              "active",
              "canceled",
              "completed",
              "failed",
              "waiting"
            ],
            "default": "waiting"
          },
          "createdAt": {
            "format": "date-time",
            "type": "string",
            "description": "Date on which the job was created."
          },
          "lastUpdatedAt": {
            "format": "date-time",
            "type": "string",
            "description": "Date on which the job was last updated."
          },
          "processedAt": {
            "format": "date-time",
            "type": "string",
            "description": "Date on which the job was processed."
          },
          "finishedAt": {
            "format": "date-time",
            "type": "string",
            "description": "Date on which the job was completed, failed, or canceled."
          },
          "cancellationRequested": {
            "type": "boolean",
            "description": "Whether or not the worker was requested to cancel processing the job",
            "default": false
          },
          "canceledByUserId": {
            "type": "string",
            "description": "Unique identifier of the user who requested cancellation.",
            "nullable": true
          },
          "organizationId": {
            "type": "string",
            "description": "Unique identifier of the organization the job belongs to"
          },
          "userId": {
            "type": "string",
            "description": "Unique identifier of the user the job belongs to",
            "nullable": true
          },
          "data": {
            "description": "Data that was passed to the workflow job worker to process the job.",
            "allOf": [
              {
                "$ref": "#/components/schemas/WorkflowJobDataResponseDto"
              }
            ]
          },
          "returnValue": {
            "description": "Result of the workflow job.",
            "allOf": [
              {
                "$ref": "#/components/schemas/EmptyReturnValueResponseDto"
              }
            ]
          },
          "failedReason": {
            "type": "string",
            "description": "The error of the workflow job, if failed",
            "nullable": true
          },
          "progress": {
            "description": "The progress information of the job",
            "nullable": true,
            "type": "object",
            "allOf": [
              {
                "$ref": "#/components/schemas/WorkflowJobProgressDto"
              }
            ]
          }
        },
        "required": [
          "id",
          "type",
          "state",
          "createdAt",
          "lastUpdatedAt",
          "cancellationRequested",
          "canceledByUserId",
          "organizationId",
          "userId",
          "data",
          "returnValue",
          "failedReason",
          "progress"
        ],
        "title": "Workflow run"
      },
      "WorkflowJobDataResponseDto": {
        "type": "object",
        "properties": {
          "trigger": {
            "type": "string",
            "description": "The trigger that caused this workflow job to be executed"
          },
          "data": {
            "type": "object",
            "description": " The data that was passed to the workflow job. This depends on the configured workflow and can be different depending on the customers needs. We have some predefined workflows where the structure is always the same (email-via-webhook, suggestion-accept) but we also support arbitrary workflows where we don't know what the data looks like. ",
            "nullable": true,
            "additionalProperties": true
          },
          "groupIndex": {
            "type": "number",
            "description": " Group index assigned to this workflow job within the grouped upload. Only set for workflow jobs created with a job group. "
          }
        },
        "required": [
          "trigger",
          "data"
        ],
        "title": "Workflow Job Data Response"
      },
      "EmptyReturnValueResponseDto": {
        "type": "object",
        "properties": {},
        "title": "Empty Return Value Response"
      },
      "WorkflowJobProgressDto": {
        "type": "object",
        "properties": {
          "progress": {
            "type": "number",
            "description": " Always 0 for workflow jobs because we can't determine how long it will take / how many nodes will be executed while the workflow is running. "
          }
        },
        "required": [
          "progress"
        ],
        "title": "Workflow Job Progress"
      },
      "ErrorArrayException": {
        "type": "object",
        "properties": {}
      },
      "WorkflowJobPostRequestDto": {
        "type": "object",
        "properties": {
          "trigger": {
            "type": "string",
            "description": "Custom trigger name configured on the enabled workflow in your organization."
          },
          "data": {
            "type": "object",
            "description": "JSON payload supplied to the workflow. Match the field names to the inputs configured in its steps."
          }
        },
        "required": [
          "trigger",
          "data"
        ],
        "title": "Workflow Job Post Request"
      },
      "PostBulkWorkflowJobByTriggerRequestDto": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "description": " The data that will be passed to the workflow job. Every entry will result in a separate workflow job. ",
            "items": {
              "anyOf": [
                {}
              ]
            }
          },
          "groupName": {
            "type": "string",
            "description": "Display name of the job group (for example, a filename or custom name).",
            "default": ""
          },
          "groupType": {
            "type": "string",
            "description": "Type of job group to be created for grouped workflow jobs.",
            "enum": [
              "default",
              "dataagents_excel_upload",
              "lead_scoring"
            ],
            "default": "default"
          },
          "trigger": {
            "type": "string",
            "description": "The trigger that caused this workflow job to be executed"
          }
        },
        "required": [
          "data",
          "trigger"
        ],
        "title": "Post Bulk Workflow Job By Trigger Request"
      },
      "PostWorkflowJobsSearchV2ResponseDto": {
        "type": "object",
        "properties": {
          "results": {
            "description": "Matching workflow jobs for the current organization and applied filters.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WorkflowJobsSearchV2ItemResponseDto"
            }
          }
        },
        "required": [
          "results"
        ],
        "title": "Post Workflow Jobs Search V2 Response"
      },
      "WorkflowJobsSearchV2ItemResponseDto": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier of the job (UUIDv4)."
          },
          "type": {
            "type": "string",
            "description": "Type of the job.",
            "enum": [
              "data_enrichment",
              "vr_download",
              "workflow",
              "digital_card",
              "crm_inventory_data_download"
            ]
          },
          "state": {
            "type": "string",
            "description": "Current lifecycle state of the job.",
            "enum": [
              "active",
              "canceled",
              "completed",
              "failed",
              "waiting"
            ],
            "default": "waiting"
          },
          "createdAt": {
            "format": "date-time",
            "type": "string",
            "description": "Date on which the job was created."
          },
          "lastUpdatedAt": {
            "format": "date-time",
            "type": "string",
            "description": "Date on which the job was last updated."
          },
          "processedAt": {
            "format": "date-time",
            "type": "string",
            "description": "Date on which the job was processed."
          },
          "finishedAt": {
            "format": "date-time",
            "type": "string",
            "description": "Date on which the job was completed, failed, or canceled."
          },
          "cancellationRequested": {
            "type": "boolean",
            "description": "Whether or not the worker was requested to cancel processing the job",
            "default": false
          },
          "canceledByUserId": {
            "type": "string",
            "description": "Unique identifier of the user who requested cancellation.",
            "nullable": true
          },
          "organizationId": {
            "type": "string",
            "description": "Unique identifier of the organization the job belongs to"
          },
          "userId": {
            "type": "string",
            "description": "Unique identifier of the user the job belongs to",
            "nullable": true
          },
          "data": {
            "description": "Data that was passed to the workflow job worker to process the job.",
            "allOf": [
              {
                "$ref": "#/components/schemas/WorkflowJobDataResponseDto"
              }
            ]
          },
          "returnValue": {
            "description": "Result of the workflow job.",
            "allOf": [
              {
                "$ref": "#/components/schemas/EmptyReturnValueResponseDto"
              }
            ]
          },
          "failedReason": {
            "type": "string",
            "description": "The error of the workflow job, if failed",
            "nullable": true
          },
          "progress": {
            "description": "The progress information of the job",
            "nullable": true,
            "type": "object",
            "allOf": [
              {
                "$ref": "#/components/schemas/WorkflowJobProgressDto"
              }
            ]
          },
          "workflowName": {
            "type": "string",
            "description": "Name of the workflow that was executed by this workflow job.",
            "nullable": true
          },
          "workflowType": {
            "type": "string",
            "description": "Type of the workflow that was executed by this workflow job.",
            "enum": [
              "dataagents",
              "visitreport_export"
            ],
            "nullable": false
          },
          "groupName": {
            "type": "string",
            "description": "Name of the job group associated with this workflow job.",
            "nullable": true
          },
          "groupType": {
            "type": "string",
            "description": "Type of the job group.",
            "enum": [
              "default",
              "dataagents_excel_upload",
              "lead_scoring"
            ],
            "nullable": true
          },
          "questionnaireId": {
            "type": "string",
            "description": "The ID of the questionnaire associated with this workflow job, if workflow type is VR export.",
            "nullable": true
          },
          "participantId": {
            "type": "string",
            "description": "The ID of the participant associated with this workflow job, if workflow type is VR export.",
            "nullable": true
          }
        },
        "required": [
          "id",
          "type",
          "state",
          "createdAt",
          "lastUpdatedAt",
          "cancellationRequested",
          "canceledByUserId",
          "organizationId",
          "userId",
          "data",
          "returnValue",
          "failedReason",
          "progress",
          "workflowName",
          "workflowType",
          "groupName",
          "groupType",
          "questionnaireId",
          "participantId"
        ],
        "title": "Workflow Jobs Search V2 Item Response"
      },
      "PostWorkflowJobsSearchV2RequestDto": {
        "type": "object",
        "properties": {
          "sortDirection": {
            "type": "string",
            "description": "Sorts workflow jobs by creation timestamp.",
            "enum": [
              "ASC",
              "DESC"
            ]
          },
          "offset": {
            "type": "number",
            "description": "Number of workflow jobs to skip before starting to collect the results.",
            "minimum": 0,
            "default": 0
          },
          "limit": {
            "type": "number",
            "description": "Maximum number of workflow jobs to return.",
            "minimum": 1,
            "maximum": 100,
            "default": 50
          },
          "filters": {
            "description": "Optional filter object used to narrow the workflow jobs returned by the search.",
            "allOf": [
              {
                "$ref": "#/components/schemas/WorkflowJobsSearchV2FiltersDto"
              }
            ]
          }
        },
        "title": "Post Workflow Jobs Search V2 Request"
      },
      "WorkflowJobsSearchV2FiltersDto": {
        "type": "object",
        "properties": {
          "types": {
            "description": "Filters workflow jobs by workflow type. ",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WorkflowJobsSearchV2TypeFilterDto"
            }
          },
          "statuses": {
            "description": "Filters workflow jobs by their status.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WorkflowJobsSearchV2StatusFilterDto"
            }
          },
          "userIds": {
            "description": "Filters workflow jobs by the unique IDs of the users.",
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/WorkflowJobsSearchV2UserIdFilterDto"
            }
          },
          "workflowIds": {
            "description": "Filters workflow jobs by workflow IDs.",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "questionnaireIds": {
            "description": "Filters workflow jobs by questionnaire IDs.",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "jobGroupIds": {
            "description": "Filters workflow jobs by job group IDs.",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "participantIds": {
            "description": "Filters workflow jobs by participant IDs.",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "jobIds": {
            "description": "Filters workflow jobs by the workflow job IDs.",
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "dateRange": {
            "description": "Filters workflow jobs by their creation timestamp range.",
            "allOf": [
              {
                "$ref": "#/components/schemas/WorkflowJobsSearchV2DateRangeFilterDto"
              }
            ]
          }
        },
        "title": "Workflow Jobs Search V2 Filters"
      },
      "WorkflowJobsSearchV2TypeFilterDto": {
        "type": "object",
        "properties": {
          "operator": {
            "type": "string",
            "description": "Determines whether matching workflow jobs must have or must not have the given workflow type.",
            "enum": [
              "IS",
              "IS_NOT"
            ]
          },
          "value": {
            "type": "string",
            "description": "The workflow type to match for this filter entry.",
            "enum": [
              "event-based",
              "continuous",
              "scheduled",
              "visitreport_export"
            ]
          }
        },
        "required": [
          "operator",
          "value"
        ],
        "title": "Workflow Jobs Search V2 Type Filter"
      },
      "WorkflowJobsSearchV2StatusFilterDto": {
        "type": "object",
        "properties": {
          "operator": {
            "type": "string",
            "description": "Determines whether matching workflow jobs must have or must not have the given status.",
            "enum": [
              "IS",
              "IS_NOT"
            ]
          },
          "value": {
            "type": "string",
            "description": "The workflow job status to match for this filter entry.",
            "enum": [
              "active",
              "canceled",
              "completed",
              "failed",
              "waiting"
            ]
          }
        },
        "required": [
          "operator",
          "value"
        ],
        "title": "Workflow Jobs Search V2 Status Filter"
      },
      "WorkflowJobsSearchV2UserIdFilterDto": {
        "type": "object",
        "properties": {
          "operator": {
            "type": "string",
            "description": "Determines whether matching workflow jobs must belong or must not belong to the given user.",
            "enum": [
              "IS",
              "IS_NOT"
            ]
          },
          "value": {
            "type": "string",
            "description": "The user ID to match for this filter entry."
          }
        },
        "required": [
          "operator",
          "value"
        ],
        "title": "Workflow Jobs Search V2 User Id Filter"
      },
      "WorkflowJobsSearchV2DateRangeFilterDto": {
        "type": "object",
        "properties": {
          "from": {
            "format": "date-time",
            "type": "string",
            "description": "Optional parameter for defining the start of the timespan of jobs to show."
          },
          "to": {
            "format": "date-time",
            "type": "string",
            "description": "Optional parameter for defining the end of the timespan of jobs to show."
          }
        },
        "title": "Workflow Jobs Search V2 Date Range Filter"
      }
    },
    "securitySchemes": {
      "x-api-key": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Use a [personal API token](/authentication/#personal-api-token)."
      }
    }
  }
}
