# `KapsoEx.Workflows.Executions`
[🔗](https://github.com/rocket4ce/kapso_ex/blob/v0.1.0/lib/kapso_ex/workflows/executions.ex#L1)

[Start and resume](https://docs.kapso.ai/docs/workflows/start-and-resume-via-api)
workflow executions and read their history.

Starting executions has an extra per-workflow burst limit (5 to 30 per
second depending on the plan); exceeding it returns `429` with
`retry_after: 1` in the `KapsoEx.Error`.

# `result`

```elixir
@type result() :: {:ok, map()} | {:error, KapsoEx.Error.t()}
```

# `get`

```elixir
@spec get(KapsoEx.Client.t(), String.t()) :: result()
```

Gets an execution with its context, variables and event history.

# `list`

```elixir
@spec list(KapsoEx.Client.t(), String.t(), map() | keyword()) :: result()
```

Lists a workflow's executions, most recent first.

Params: `status`, `created_after`, `created_before`,
`whatsapp_conversation_id`, `limit`, `before`, `after`.

# `list_events`

```elixir
@spec list_events(KapsoEx.Client.t(), String.t(), map() | keyword()) :: result()
```

Lists an execution's events, most recent first. Params: `event_type`, `limit`, `before`, `after`.

# `list_for_conversation`

```elixir
@spec list_for_conversation(KapsoEx.Client.t(), String.t(), map() | keyword()) ::
  result()
```

Lists the workflow executions of a WhatsApp conversation, most recent
first. Params: `status`, `limit`, `before`, `after`.

# `resume`

```elixir
@spec resume(KapsoEx.Client.t(), String.t(), String.t() | map() | list(), keyword()) ::
  result()
```

Resumes an execution in `waiting` status (for example at a wait for
response step), delivering `data` as the incoming message.

`data` is a string, map or list.

## Options

  * `:kind` - message kind, for example `"text"`.
  * `:variables` - variables to merge into the execution.

## Examples

    Executions.resume(client, execution_id, "yes", kind: "text", variables: %{confirmed: true})

# `start`

```elixir
@spec start(KapsoEx.Client.t(), String.t(), map() | keyword()) :: result()
```

Starts an execution asynchronously (`202`, with an `id` and
`tracking_id`). The workflow must be active.

Attributes: `phone_number` (E.164) and/or `recipient` (business-scoped
user ID), `phone_number_id`, `variables`, `context`, `initial_data`.

    Executions.start(client, workflow_id,
      phone_number: "+56961567267",
      phone_number_id: "647015955153740",
      variables: %{order_id: "ORD-1234"}
    )

# `update_status`

```elixir
@spec update_status(KapsoEx.Client.t(), String.t(), String.t()) :: result()
```

Sets the status of an execution: `"ended"`, `"handoff"` or `"waiting"`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
