# Create a drip workflow

`POST /v1/workflows`

- Authentication: required (Bearer token)
- Required scope: `api.workflows.manage`

Creates a managed drip-workflow definition from a `.flow` source. `key`
is the stable org-unique handle other calls reference the workflow by
and is immutable afterwards; a key already in use returns
`409 conflict`.

**A source that does not validate is still a `201`.** The row is stored
with `status: invalid` and `invalid_reason`, and the response carries
the stored source with every positioned finding in `diagnostics` — so a
definition is never silently dropped, and a caller can see both that its
work landed and why it cannot run yet. `422` is reserved for a request
that could not be stored at all (no `key`, no `name`, no `source`, a key
that is not a slug).

A created workflow is a **draft**: it enrols nobody and sends nothing
until `POST /v1/workflows/{id}/activate`. Do not write SendFlow from
memory — the grammar is published at
<https://www.sendlang.com/docs/reference/grammar>, and a guessed
definition usually nearly parses.

## Request body

Content type: `application/json`

```json
{
  "key": "string",
  "name": "string",
  "description": "string",
  "source": "string"
}
```

## Example request

```bash
curl -X POST 'https://api.sendops.dev/v1/workflows' \
  -H "Authorization: Bearer $SENDOPS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"key":"string","name":"string","description":"string","source":"string"}'
```

## Responses

### 201 — The created workflow, in `draft` or `invalid`

Content type: `application/json`

```json
{
  "id": "00000000-0000-0000-0000-000000000000",
  "name": "string",
  "key": "string",
  "description": "string",
  "status": "string",
  "invalid_reason": "string",
  "require_send_approval": true,
  "send_mode": "live",
  "shadow_started_at": "2026-05-17T20:00:00Z",
  "shadow_cohort_list_id": "00000000-0000-0000-0000-000000000000",
  "shadow_cohort": {
    "id": "00000000-0000-0000-0000-000000000000",
    "key": "string",
    "name": "string",
    "member_count": 0
  },
  "current_version": 0,
  "run_counts": {},
  "created_at": "2026-05-17T20:00:00Z",
  "updated_at": "2026-05-17T20:00:00Z",
  "source": "string",
  "content_hash": "string",
  "warnings": [
    "string"
  ],
  "diagnostics": [
    {
      "line": 0,
      "column": 0,
      "severity": "string",
      "message": "string"
    }
  ],
  "requires": [
    {
      "kind": "template",
      "key": "string",
      "status": "ok",
      "detail": "string",
      "fix": "string"
    }
  ]
}
```

### 401 — Missing, malformed, or unknown API key

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```

### 403 — Key lacks the required scope or plan limit violated

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```

### 409 — The mutation is rejected by a state rule rather than a bad request. The
`code` is `conflict`.

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```

### 422 — A query parameter, path value or body field failed validation.

The body is a `validation_failed` Problem. When the refusal is about a
reference — a segment key, template slug, topic or attribute name the
organization does not have — it additionally carries `validation_code`,
`field`, `line`/`column`, `missing`, `candidates` and `next_step`, so a
client can correct the call without a second round of guessing. See
`ValidationProblem`.

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ],
  "validation_code": "invalid_syntax",
  "field": "string",
  "line": 0,
  "column": 0,
  "missing": [
    {
      "kind": "segment",
      "key": "string"
    }
  ],
  "candidates": {},
  "next_step": "string"
}
```

### 429 — Per-org rate limit exceeded

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```

### 500 — Unexpected server-side failure. The `code` is `internal_error`. The
`request_id` field can be quoted to SendOps support to investigate.

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```
