# Workflows

> Automations: a trigger and the steps it runs, and their runs. 14 endpoints in the Unvop API.

Automations: a trigger and the steps it runs, and their runs.

## List workflow nodes

`GET /v1/workflow-nodes`

Scope: `workflows:read`.

Every node a workflow can use: triggers (a form is sent, an entry changes, a schedule, a webhook, a payment…) and steps (conditions, contacts, emails, collection writes, AI sort, summarise and draft, HTTP requests, responses). Each lists its config fields and what it outputs, so you can write a valid graph.

### Response 200

- `items` (array of objects, required)
  - `type` (string, required)
  - `label` (string, required)
  - `category` (string, required)
  - `description` (string)
  - `fields` (array)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/workflow-nodes \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## List workflow templates

`GET /v1/sites/{siteId}/workflow-templates`

Scope: `workflows:read`.

Ready-made workflows to start from (welcome new leads, notify on payment…). Pass a template id to POST /sites/{siteId}/workflows.

### Path parameters

- `siteId` (string, required): The site’s id.

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `name` (string, required)
  - `description` (string, required)
  - `graph` (object, required): A workflow graph: one trigger node and the steps it leads to.
    - `nodes` (array of objects, required): (up to 100 items)
      - `id` (string, required): (up to 40 characters)
      - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
      - `label` (string): (up to 120 characters)
      - `config` (object, required): (default {})
      - `x` (number, required): (default 0)
      - `y` (number, required): (default 0)
    - `edges` (array of objects, required): (up to 300 items)
      - `from` (string, required)
      - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
      - `to` (string, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/workflow-templates \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## List workflows

`GET /v1/sites/{siteId}/workflows`

Scope: `workflows:read`.

The site’s workflows, with their draft and published graphs and whether they are on.

### Path parameters

- `siteId` (string, required): The site’s id.

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `name` (string, required)
  - `description` (string, required)
  - `enabled` (boolean, required): Runs when its trigger fires. Only a published workflow can be on.
  - `draft` (object, required): A workflow graph: one trigger node and the steps it leads to.
    - `nodes` (array of objects, required): (up to 100 items)
      - `id` (string, required): (up to 40 characters)
      - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
      - `label` (string): (up to 120 characters)
      - `config` (object, required): (default {})
      - `x` (number, required): (default 0)
      - `y` (number, required): (default 0)
    - `edges` (array of objects, required): (up to 300 items)
      - `from` (string, required)
      - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
      - `to` (string, required)
  - `live` (object, required, nullable): The published graph that runs.
    - `nodes` (array of objects, required): (up to 100 items)
      - `id` (string, required): (up to 40 characters)
      - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
      - `label` (string): (up to 120 characters)
      - `config` (object, required): (default {})
      - `x` (number, required): (default 0)
      - `y` (number, required): (default 0)
    - `edges` (array of objects, required): (up to 300 items)
      - `from` (string, required)
      - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
      - `to` (string, required)
  - `hook` (any): For webhook workflows: the address it answers at.
- `cursor` (string, nullable): Pass as ?cursor= to get the next page. Null when there are no more.
- `total` (integer): How many there are in all, when the list knows.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/workflows \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Create a workflow

`POST /v1/sites/{siteId}/workflows`

Scope: `workflows:write`.

Create a workflow from a template or your own graph. It starts as a draft: test it, publish it, then turn it on with PATCH { enabled: true }.

### Path parameters

- `siteId` (string, required): The site’s id.

### Headers

- `Idempotency-Key` (string): Send the same key to repeat this request safely; the first answer is replayed for 24 hours. (up to 200 characters)

### Request body (JSON)

- `name` (string): (up to 120 characters)
- `description` (string): (up to 500 characters)
- `templateId` (string)
- `draft` (object): A workflow graph: one trigger node and the steps it leads to.
  - `nodes` (array of objects, required): (up to 100 items)
    - `id` (string, required): (up to 40 characters)
    - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
    - `label` (string): (up to 120 characters)
    - `config` (object): (default {})
    - `x` (number): (default 0)
    - `y` (number): (default 0)
  - `edges` (array of objects, required): (up to 300 items)
    - `from` (string, required)
    - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
    - `to` (string, required)

### Response 201

- `id` (string, required)
- `name` (string, required)
- `description` (string, required)
- `enabled` (boolean, required): Runs when its trigger fires. Only a published workflow can be on.
- `draft` (object, required): A workflow graph: one trigger node and the steps it leads to.
  - `nodes` (array of objects, required): (up to 100 items)
    - `id` (string, required): (up to 40 characters)
    - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
    - `label` (string): (up to 120 characters)
    - `config` (object, required): (default {})
    - `x` (number, required): (default 0)
    - `y` (number, required): (default 0)
  - `edges` (array of objects, required): (up to 300 items)
    - `from` (string, required)
    - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
    - `to` (string, required)
- `live` (object, required, nullable): The published graph that runs.
  - `nodes` (array of objects, required): (up to 100 items)
    - `id` (string, required): (up to 40 characters)
    - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
    - `label` (string): (up to 120 characters)
    - `config` (object, required): (default {})
    - `x` (number, required): (default 0)
    - `y` (number, required): (default 0)
  - `edges` (array of objects, required): (up to 300 items)
    - `from` (string, required)
    - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
    - `to` (string, required)
- `hook` (any): For webhook workflows: the address it answers at.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/workflows \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "name": "Tag new leads",
    "draft": {
      "nodes": [
        {
          "id": "trigger",
          "type": "trigger.form",
          "config": {
            "form": "contact"
          }
        },
        {
          "id": "tag",
          "type": "people.upsert",
          "config": {
            "email": "{{trigger.contact.email}}",
            "tags": "website"
          }
        }
      ],
      "edges": [
        {
          "from": "trigger",
          "port": "next",
          "to": "tag"
        }
      ]
    }
  }'
```

## Get a workflow

`GET /v1/sites/{siteId}/workflows/{workflowId}`

Scope: `workflows:read`.

One workflow with its draft and published graphs.

### Path parameters

- `siteId` (string, required): The site’s id.
- `workflowId` (string, required)

### Response 200

- `id` (string, required)
- `name` (string, required)
- `description` (string, required)
- `enabled` (boolean, required): Runs when its trigger fires. Only a published workflow can be on.
- `draft` (object, required): A workflow graph: one trigger node and the steps it leads to.
  - `nodes` (array of objects, required): (up to 100 items)
    - `id` (string, required): (up to 40 characters)
    - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
    - `label` (string): (up to 120 characters)
    - `config` (object, required): (default {})
    - `x` (number, required): (default 0)
    - `y` (number, required): (default 0)
  - `edges` (array of objects, required): (up to 300 items)
    - `from` (string, required)
    - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
    - `to` (string, required)
- `live` (object, required, nullable): The published graph that runs.
  - `nodes` (array of objects, required): (up to 100 items)
    - `id` (string, required): (up to 40 characters)
    - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
    - `label` (string): (up to 120 characters)
    - `config` (object, required): (default {})
    - `x` (number, required): (default 0)
    - `y` (number, required): (default 0)
  - `edges` (array of objects, required): (up to 300 items)
    - `from` (string, required)
    - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
    - `to` (string, required)
- `hook` (any): For webhook workflows: the address it answers at.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/workflows/wfl_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Change a workflow

`PATCH /v1/sites/{siteId}/workflows/{workflowId}`

Scope: `workflows:write`.

Rename it, replace its draft graph, or turn it on or off (enabled). Only a published workflow can be turned on, and only owners and admins can turn workflows on or off.

### Path parameters

- `siteId` (string, required): The site’s id.
- `workflowId` (string, required)

### Request body (JSON)

- `name` (string): (up to 120 characters)
- `description` (string): (up to 500 characters)
- `draft` (object): A workflow graph: one trigger node and the steps it leads to.
  - `nodes` (array of objects, required): (up to 100 items)
    - `id` (string, required): (up to 40 characters)
    - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
    - `label` (string): (up to 120 characters)
    - `config` (object): (default {})
    - `x` (number): (default 0)
    - `y` (number): (default 0)
  - `edges` (array of objects, required): (up to 300 items)
    - `from` (string, required)
    - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
    - `to` (string, required)
- `enabled` (boolean)

### Response 200

- `id` (string, required)
- `name` (string, required)
- `description` (string, required)
- `enabled` (boolean, required): Runs when its trigger fires. Only a published workflow can be on.
- `draft` (object, required): A workflow graph: one trigger node and the steps it leads to.
  - `nodes` (array of objects, required): (up to 100 items)
    - `id` (string, required): (up to 40 characters)
    - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
    - `label` (string): (up to 120 characters)
    - `config` (object, required): (default {})
    - `x` (number, required): (default 0)
    - `y` (number, required): (default 0)
  - `edges` (array of objects, required): (up to 300 items)
    - `from` (string, required)
    - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
    - `to` (string, required)
- `live` (object, required, nullable): The published graph that runs.
  - `nodes` (array of objects, required): (up to 100 items)
    - `id` (string, required): (up to 40 characters)
    - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
    - `label` (string): (up to 120 characters)
    - `config` (object, required): (default {})
    - `x` (number, required): (default 0)
    - `y` (number, required): (default 0)
  - `edges` (array of objects, required): (up to 300 items)
    - `from` (string, required)
    - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
    - `to` (string, required)
- `hook` (any): For webhook workflows: the address it answers at.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X PATCH https://api.unvop.com/v1/sites/site_123/workflows/wfl_123 \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Ana",
    "description": "Building the homepage"
  }'
```

## Delete a workflow

`DELETE /v1/sites/{siteId}/workflows/{workflowId}`

Scope: `workflows:write`.

Delete a workflow and its runs. Owners and admins only.

### Path parameters

- `siteId` (string, required): The site’s id.
- `workflowId` (string, required)

### Response 200

- `ok` (true, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X DELETE https://api.unvop.com/v1/sites/site_123/workflows/wfl_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Publish a workflow

`POST /v1/sites/{siteId}/workflows/{workflowId}/publish`

Scope: `workflows:write`.

Make the draft graph the one that runs. Problems that would stop it running come back as details.problems. A webhook workflow’s first publish returns hookSecret, its signing secret, once. Owners and admins only.

### Path parameters

- `siteId` (string, required): The site’s id.
- `workflowId` (string, required)

### Response 200

- `id` (string, required)
- `name` (string, required)
- `description` (string, required)
- `enabled` (boolean, required): Runs when its trigger fires. Only a published workflow can be on.
- `draft` (object, required): A workflow graph: one trigger node and the steps it leads to.
  - `nodes` (array of objects, required): (up to 100 items)
    - `id` (string, required): (up to 40 characters)
    - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
    - `label` (string): (up to 120 characters)
    - `config` (object, required): (default {})
    - `x` (number, required): (default 0)
    - `y` (number, required): (default 0)
  - `edges` (array of objects, required): (up to 300 items)
    - `from` (string, required)
    - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
    - `to` (string, required)
- `live` (object, required, nullable): The published graph that runs.
  - `nodes` (array of objects, required): (up to 100 items)
    - `id` (string, required): (up to 40 characters)
    - `type` (string, required): A node type from GET /workflow-nodes, like trigger.form or people.upsert. (up to 40 characters)
    - `label` (string): (up to 120 characters)
    - `config` (object, required): (default {})
    - `x` (number, required): (default 0)
    - `y` (number, required): (default 0)
  - `edges` (array of objects, required): (up to 300 items)
    - `from` (string, required)
    - `port` (string, required): The output port: "next", or "true"/"false" after logic.if, or "pass" after logic.filter.
    - `to` (string, required)
- `hook` (any): For webhook workflows: the address it answers at.
- `hookSecret` (string)

### Errors

- `400`: The request is malformed.
- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X POST https://api.unvop.com/v1/sites/site_123/workflows/wfl_123/publish \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Test a workflow

`POST /v1/sites/{siteId}/workflows/{workflowId}/test`

Scope: `workflows:write`.

Run the draft graph once as a test, with the trigger payload you send or the trigger’s sample. Follow the run with GET /sites/{siteId}/runs/{runId}.

### Path parameters

- `siteId` (string, required): The site’s id.
- `workflowId` (string, required)

### Request body (JSON)

- `trigger` (any): The payload the trigger would carry.

### Response 200

- `runId` (string, required)

### Errors

- `400`: The request is malformed.
- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/workflows/wfl_123/test \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "trigger": {}
  }'
```

## Run a workflow

`POST /v1/sites/{siteId}/workflows/{workflowId}/run`

Scope: `workflows:write`.

Run the published graph now with the input you send, as its Run button does. Follow the run with GET /sites/{siteId}/runs/{runId}.

### Path parameters

- `siteId` (string, required): The site’s id.
- `workflowId` (string, required)

### Request body (JSON)

- `input` (object)

### Response 200

- `runId` (string, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/workflows/wfl_123/run \
  -H "Authorization: Bearer $UNVOP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": {}
  }'
```

## Rotate a webhook secret

`POST /v1/sites/{siteId}/workflows/{workflowId}/hook-secret`

Scope: `workflows:write`.

Make a new signing secret for a published webhook workflow. The old one stops working. Shown once. Owners and admins only.

### Path parameters

- `siteId` (string, required): The site’s id.
- `workflowId` (string, required)

### Response 200

- `secret` (string, required)

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl -X POST https://api.unvop.com/v1/sites/site_123/workflows/wfl_123/hook-secret \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## List a workflow’s runs

`GET /v1/sites/{siteId}/workflows/{workflowId}/runs`

Scope: `workflows:read`.

The workflow’s recent runs, newest first.

### Path parameters

- `siteId` (string, required): The site’s id.
- `workflowId` (string, required)

### Query parameters

- `limit` (integer): (min 1; max 200)

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `workflowId` (string, required)
  - `status` (string, required): One of `queued`, `running`, `waiting`, `succeeded`, `failed`, `cancelled`.
  - `source` (string)
  - `steps` (array)
  - `createdAt` (string, required): An ISO 8601 timestamp.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/workflows/wfl_123/runs \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## List runs

`GET /v1/sites/{siteId}/runs`

Scope: `workflows:read`.

Recent runs of every workflow on the site, newest first. Filter by workflow or status.

### Path parameters

- `siteId` (string, required): The site’s id.

### Query parameters

- `workflow` (string)
- `status` (string): One of `queued`, `running`, `waiting`, `succeeded`, `failed`, `cancelled`.
- `limit` (integer): (min 1; max 200)

### Response 200

- `items` (array of objects, required)
  - `id` (string, required)
  - `workflowId` (string, required)
  - `status` (string, required): One of `queued`, `running`, `waiting`, `succeeded`, `failed`, `cancelled`.
  - `source` (string)
  - `steps` (array)
  - `createdAt` (string, required): An ISO 8601 timestamp.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `422`: The body is invalid; details say which values.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/runs \
  -H "Authorization: Bearer $UNVOP_KEY"
```

## Get a run

`GET /v1/sites/{siteId}/runs/{runId}`

Scope: `workflows:read`.

One run with each step: what went in, what came out, and any error.

### Path parameters

- `siteId` (string, required): The site’s id.
- `runId` (string, required)

### Response 200

- `id` (string, required)
- `workflowId` (string, required)
- `status` (string, required): One of `queued`, `running`, `waiting`, `succeeded`, `failed`, `cancelled`.
- `source` (string)
- `steps` (array)
- `createdAt` (string, required): An ISO 8601 timestamp.

### Errors

- `401`: No key, or the key isn’t valid.
- `403`: The key lacks the scope (insufficient_scope) or the role this needs, or the site’s plan lacks the feature (feature_not_in_plan).
- `404`: Not found, or not reachable with this key.
- `429`: Too many requests; wait for RateLimit-Reset seconds.

### Example

```sh
curl https://api.unvop.com/v1/sites/site_123/runs/run_123 \
  -H "Authorization: Bearer $UNVOP_KEY"
```
