Workflow

Create a workflow

POST/api/v1/workflows

Creates a workflow automation: when one of the trigger events happens and the conditions match, the actions run in order.

  • Get the trigger, condition and action ids, and the value each one takes, from GET /api/v1/workflows/schema. Every key, operator and value is checked against it.
  • conditions is a list of groups. Every group must match (AND); within a group any one condition may match (OR). Send [] for a workflow that always runs.
  • A new workflow is always created disabled and is placed last in the priority order. Enable and reorder it in the app. enabled in the body is ignored, and priority is refused.
  • Only type: workflow can be created. SLA policies are managed in the app.
  • A workflow is refused with 409 as a duplicate when an existing workflow of the same type has the same trigger and conditions and already has every kind of action the new one has. Workflows with the when_manually_triggered trigger are exempt.

Send dry_run=true to validate the body without creating anything. A dry run answers 200 with valid and the list of errors, and when valid, the workflow as it would be stored.

Required ability: workflows:write.

Request

Authorization

Bearer Token

Provide your API token in the Authorization header. See Authentication to issue one.

Example:Authorization: Bearer ********************

Query Params
  • dry_runbooleanoptional

    Set to true (or 1) to check the request without changing anything. The response tells you what would happen: the items that would be updated and skipped for a bulk request, or the validation result for a workflow. A dry run does not need an Idempotency-Key.

    dry_run can also be sent as a top-level field of the JSON body; the query parameter wins when both are sent. Any value other than true, false, 1 or 0 is refused with 400. Endpoints that do not list this parameter refuse dry_run=true with 400.

    Default:false

    Example:true

Header Params
  • Idempotency-Keystringrequired

    A unique value you choose for this write, for example a UUID, so that a retry cannot apply the change twice. 1 to 255 visible ASCII characters, no spaces. On endpoints that support dry_run, the header is not needed for a dry run.

    • A key belongs to your API token and to one endpoint (method and path): the same value on another endpoint is a different key.
    • Sending the same key with the same body again within 24 hours does not repeat the write. You get the first response back, with the header Idempotent-Replayed: true. Error responses with a 4xx status are replayed too.
    • The same key with a different body is refused with 422.
    • While the first request is still running, a second one with the same key gets 409.
    • A response with a 5xx status is not kept: retry with the same key.
    • A missing key, or one that is not 1 to 255 visible ASCII characters, is refused with 400.
    • If the key cannot be checked, the request is refused with 503 and nothing is changed.

    Example:8f14e45f-ceea-467f-a8d4-5b2c1e0f9a3d

Body Paramsapplication/json
  • namestringrequired

    Must not be blank.

  • typestringrequired

    Allowed values:"workflow"

  • triggerWorkflowTriggerrequired
    Child attributes
    • eventsarray[string]required

      Trigger ids from GET /api/v1/workflows/schema. The workflow runs when any of them happens. A trigger marked exclusive in the schema cannot be combined with others.

      Example:["when_chat_room_is_open"]

    • delaySecondsintegeroptional

      Seconds to wait. Required with a trigger marked supportsDelay in the schema, and not allowed otherwise.

  • conditionsarray[array[WorkflowCondition]]required

    Groups of conditions. Every group must match (AND); within a group any one condition may match (OR). Send [] for no conditions.

    Child attributes
    • keystringrequired

      A condition id from GET /api/v1/workflows/schema.

      Example:contact.name

    • operatorstring | nulloptional

      One of the operators the schema lists for this condition, for example equal or contains.

    • valuesanyoptional

      What to compare with. Its shape depends on the condition (valueType in the schema): usually a string, for some conditions an object.

    • uiValuestring | nulloptional

      Display text used by the app's workflow builder. Optional.

    • uiFilterOperatorstring | nulloptional

      Display text used by the app's workflow builder. Optional.

    • typestring | nulloptional

      Display hint used by the app's workflow builder. Optional.

    • badgesanyoptional

      Display data used by the app's workflow builder. Optional.

  • actionsarray[WorkflowAction]required

    The actions, run in order.

    Child attributes
    • keystringrequired

      An action id from GET /api/v1/workflows/schema.

      Example:auto.assign

    • valuesanyoptional

      The action's settings. Its shape depends on the action (valueType and fields in the schema): a string or an object.

    • uiValuestring | nulloptional

      Display text used by the app's workflow builder. Optional.

    • stampbooleanoptional

      Show the action in the inbox when it runs. Only for actions marked supportsStamp in the schema.

  • enabledbooleanoptional

    Accepted but ignored. A new workflow is always disabled.

  • dry_runbooleanoptional

    Same as the dry_run query parameter, which wins when both are sent.

Responses

200

Returned for dry_run=true only: the validation result. Nothing was created.

  • dryRunbooleanrequired

    Allowed values:true

  • validbooleanrequired
  • errorsarray[WorkflowFieldError]required
    Child attributes
    • pathstringrequired

      The field the problem is in, for example trigger.events[0] or actions[2].values.queueId. $ means the whole body.

    • messagestringrequired
  • workflowWorkflow | nullrequired

    When valid, the workflow as it would be stored; otherwise null.

    Possible formats
    • Option 1Workflow
      Child attributes
      • idstring<uuid> | nulloptional

        null only in the preview of a create dry run.

      • namestringoptional
      • typestringoptional

        Allowed values:"workflow", "sla", "ticket_sla"

      • priorityinteger | nulloptional

        Position in the evaluation order within its type; 1 is first.

      • enabledbooleanoptional
      • custombooleanoptional

        true for a workflow that agents run by hand (trigger when_manually_triggered).

      • triggerWorkflowTriggeroptional
        Child attributes
        • eventsarray[string]required

          Trigger ids from GET /api/v1/workflows/schema. The workflow runs when any of them happens. A trigger marked exclusive in the schema cannot be combined with others.

          Example:["when_chat_room_is_open"]

        • delaySecondsintegeroptional

          Seconds to wait. Required with a trigger marked supportsDelay in the schema, and not allowed otherwise.

      • conditionsarray[array[WorkflowCondition]]optional

        Groups of conditions. Every group must match (AND); within a group any one condition may match (OR). An empty list means always.

        Child attributes
        • keystringrequired

          A condition id from GET /api/v1/workflows/schema.

          Example:contact.name

        • operatorstring | nulloptional

          One of the operators the schema lists for this condition, for example equal or contains.

        • valuesanyoptional

          What to compare with. Its shape depends on the condition (valueType in the schema): usually a string, for some conditions an object.

        • uiValuestring | nulloptional

          Display text used by the app's workflow builder. Optional.

        • uiFilterOperatorstring | nulloptional

          Display text used by the app's workflow builder. Optional.

        • typestring | nulloptional

          Display hint used by the app's workflow builder. Optional.

        • badgesanyoptional

          Display data used by the app's workflow builder. Optional.

      • actionsarray[WorkflowAction]optional

        The actions, run in order.

        Child attributes
        • keystringrequired

          An action id from GET /api/v1/workflows/schema.

          Example:auto.assign

        • valuesanyoptional

          The action's settings. Its shape depends on the action (valueType and fields in the schema): a string or an object.

        • uiValuestring | nulloptional

          Display text used by the app's workflow builder. Optional.

        • stampbooleanoptional

          Show the action in the inbox when it runs. Only for actions marked supportsStamp in the schema.

      • createdAtstring<date-time> | nulloptional
      • updatedAtstring<date-time> | nulloptional
    • Option 2null
201

The workflow that was created. It is disabled.

  • idstring<uuid> | nulloptional

    null only in the preview of a create dry run.

  • namestringoptional
  • typestringoptional

    Allowed values:"workflow", "sla", "ticket_sla"

  • priorityinteger | nulloptional

    Position in the evaluation order within its type; 1 is first.

  • enabledbooleanoptional
  • custombooleanoptional

    true for a workflow that agents run by hand (trigger when_manually_triggered).

  • triggerWorkflowTriggeroptional
    Child attributes
    • eventsarray[string]required

      Trigger ids from GET /api/v1/workflows/schema. The workflow runs when any of them happens. A trigger marked exclusive in the schema cannot be combined with others.

      Example:["when_chat_room_is_open"]

    • delaySecondsintegeroptional

      Seconds to wait. Required with a trigger marked supportsDelay in the schema, and not allowed otherwise.

  • conditionsarray[array[WorkflowCondition]]optional

    Groups of conditions. Every group must match (AND); within a group any one condition may match (OR). An empty list means always.

    Child attributes
    • keystringrequired

      A condition id from GET /api/v1/workflows/schema.

      Example:contact.name

    • operatorstring | nulloptional

      One of the operators the schema lists for this condition, for example equal or contains.

    • valuesanyoptional

      What to compare with. Its shape depends on the condition (valueType in the schema): usually a string, for some conditions an object.

    • uiValuestring | nulloptional

      Display text used by the app's workflow builder. Optional.

    • uiFilterOperatorstring | nulloptional

      Display text used by the app's workflow builder. Optional.

    • typestring | nulloptional

      Display hint used by the app's workflow builder. Optional.

    • badgesanyoptional

      Display data used by the app's workflow builder. Optional.

  • actionsarray[WorkflowAction]optional

    The actions, run in order.

    Child attributes
    • keystringrequired

      An action id from GET /api/v1/workflows/schema.

      Example:auto.assign

    • valuesanyoptional

      The action's settings. Its shape depends on the action (valueType and fields in the schema): a string or an object.

    • uiValuestring | nulloptional

      Display text used by the app's workflow builder. Optional.

    • stampbooleanoptional

      Show the action in the inbox when it runs. Only for actions marked supportsStamp in the schema.

  • createdAtstring<date-time> | nulloptional
  • updatedAtstring<date-time> | nulloptional
400

The body is not valid JSON, dry_run is not valid, or the Idempotency-Key header is missing or malformed.

  • messagestringrequired
  • errorstringoptional
  • statusCodeintegerrequired
401

The API token is missing or invalid.

403

The API token does not have the ability this endpoint requires. See "Token abilities" in the introduction.

  • messagestringrequired
  • errorstringoptional
  • statusCodeintegerrequired
409

The workflow duplicates an existing one (same trigger and conditions, and no new kind of action), or a request with the same Idempotency-Key is still running.

  • messagestringrequired
  • errorstringoptional
  • statusCodeintegerrequired
422

The workflow is not valid; errors lists every problem with the path of the field. message is the problem itself when there is only one. Also returned, without errors, when the Idempotency-Key was already used with a different body.

  • messagestringrequired
  • errorstringoptional
  • statusCodeintegerrequired
  • errorsarray[WorkflowFieldError]optional
    Child attributes
    • pathstringrequired

      The field the problem is in, for example trigger.events[0] or actions[2].values.queueId. $ means the whole body.

    • messagestringrequired
503

The Idempotency-Key could not be checked, so the request was not processed. Nothing was changed; retry later.

  • messagestringrequired
  • errorstringoptional
  • statusCodeintegerrequired