Create a workflow definition

Create a new workflow definition. To create a workflow definition, you must register with SimWorkflow and have a valid Personal Access Token to authenticate requests. Anonymous requests are never allowed to create workflow definitions.

Request syntax

POST /workflow-definitions HTTP/1.1
Host: api.simworkflow.com
Authorization: Bearer ${PERSONAL_ACCESS_TOKEN}
Content-Type: application/json
${WORKFLOW_DEFINITION}

Request headers

Authorization

Bearer ${PERSONAL_ACCESS_TOKEN}

Content-Type

application/json

Request body

The Workflow definition JSON object

Response syntax

HTTP/1.1 200 OK
String

Response elements

If the action is successful, the service sends back an HTTP 200 response.

The response returns the body contains the Id for the created workflow definition as String.

Errors

HTTP status code

Description

400

When the workflow definition object is not valid.

See also general errors.

cURL example: workflow definition with parallel task and a join task

POST /workflow-definitions

curl \
--request "POST" \
--header "Authorization: Bearer ${PERSONAL_ACCESS_TOKEN}" \
--header "Content-Type: application/json" \
--url "https://api.simworkflow.com/workflow-definitions" \
--data '{
  "name": "Customer Details",
  "startTask": "Lookup Customer Details",
  "tasks": {
    "Lookup Customer Details": {
        "type": "Parallel",
        "branches": [
          {
            "startTask": "Lookup Address",
            "tasks": {
              "Lookup Address": {
                "type": "Http",
                "httpRequest": {
                  "url": "https://nominatim.openstreetmap.org/search?addressdetails=1&format=json&q=Melbourne"
                },
                "end": true
              }
            }
          },
          {
            "startTask": "Lookup Phone Number",
            "tasks": {
              "Lookup Phone Number": {
                "type": "Http",
                "credentials": "CredentialsId",
                "httpRequest": {
                  "url": "https://lookups.twilio.com/v2/PhoneNumbers/+15108675310?Fields=line_type_intelligence"
                },
                "end": true
              }
            }
          }
        ],
        "nextTask": "Join Task"
      },
      "Join Task": {
        "type": "Terminate",
        "terminationStatus": "Completed"
      }
  }
}'

RESPONSE

HTTP/1.1 200 OK
"0NRnuLkcXGPHmtV5qLUErk"

cURL example: invalid workflow definition with missing required next task

POST /workflow-definitions

curl \
--request "POST" \
--header "Authorization: Bearer ${PERSONAL_ACCESS_TOKEN}" \
--header "Content-Type: application/json" \
--url "https://api.simworkflow.com/workflow-definitions" \
--data '{
  "name": "Customer Details",
  "startTask": "Lookup Customer Details",
  "tasks": {
    "Lookup Customer Details": {
        "type": "Parallel",
        "branches": [
          {
            "startTask": "Lookup Address",
            "tasks": {
              "Lookup Address": {
                "type": "Http",
                "httpRequest": {
                  "url": "https://nominatim.openstreetmap.org/search?addressdetails=1&format=json&q=Melbourne"
                },
                "end": true
              }
            }
          },
          {
            "startTask": "Lookup Phone Number",
            "tasks": {
              "Lookup Phone Number": {
                "type": "Http",
                "credentials": "CredentialsId",
                "httpRequest": {
                  "url": "https://lookups.twilio.com/v2/PhoneNumbers/+15108675310?Fields=line_type_intelligence"
                },
                "end": true
              }
            }
          }
        ],
        "nextTask": "Join Task"
      }
  }
}'

RESPONSE

HTTP/1.1 400 Bad Request
{
  "status": 400,
  "error": "Bad Request",
  "fieldErrors": {
    "workflowDefinition.tasks[Lookup Customer Details].nextTask": {
      "field": "workflowDefinition.tasks[Lookup Customer Details].nextTask",
      "message": "Task definition should have a valid next task",
      "value": null
    }
  }
}