# Validate a flow graph

`POST https://api.morevoice.ai/v1/flows/validate`

Checks a graph without saving it: the errors that would block publishing, plus warnings and tasks. A malformed graph answers 400.

Authenticate with a secret API key: `Authorization: Bearer $MOREVOICE_API_KEY`.

Operation ID: `flows_validate`.

## Parameters

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `MoreVoice-Version` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `Idempotency-Key` | `string` | no | A unique key (for example a UUID) that makes this request safe to retry: for 24 hours, a retry with the same key and parameters returns the first response instead of acting twice. |

## Request body

Required, `application/json`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `graph` | `FlowGraphParamsInput` | yes | A whole graph to write. Nodes are matched to the stored draft by `key`. |
| `graph.nodes` | `FlowNodeParamsInput[]` | yes | — |
| `graph.kind` | `"voice" \| "agent_script" \| "ivr"` | no | Must be the flow's kind (default: the flow's). |
| `graph.schema_version` | `1` | no | — |
| `graph.settings` | `object` | no | Merged with the stored settings. |
| `graph.variables` | `object[]` | no | Default: the stored variables. |

Example:

```json
{
  "graph": {
    "kind": "voice",
    "nodes": [
      {
        "key": "start",
        "transitions": [
          {
            "condition": {
              "kind": "always"
            },
            "next": null
          }
        ],
        "type": "start"
      }
    ]
  }
}
```

## Responses

### 200 OK

OK Returns `FlowValidation`.

| Field | Type | Description |
| --- | --- | --- |
| `object` | `"flow_validation"` | — |
| `valid` | `boolean` | No errors: it can be published. |
| `issues` | `object[]` | — |

Example:

```json
{
  "issues": [
    {
      "code": "dead_end",
      "field": null,
      "message": "This node has an output that leads nowhere.",
      "node_key": "ask_id",
      "severity": "error",
      "transition_key": "t_fail"
    }
  ],
  "object": "flow_validation",
  "valid": false
}
```

### 400 Bad Request

The request is invalid: a parameter is missing, malformed or unknown, or the version header is unknown. Returns `ErrorEnvelope`.

### 401 Unauthorized

No valid API key was sent. Returns `ErrorEnvelope`.

### 403 Forbidden

The key may not do this (a missing scope, a plan limit, or a compliance block). Returns `ErrorEnvelope`.

### 409 Conflict

The request conflicts with the object's state, or the Idempotency-Key was reused with other parameters. Returns `ErrorEnvelope`.

### 429 Too Many Requests

Too many requests, or no call capacity right now. Retry after the Retry-After delay. Returns `ErrorEnvelope`.

### 500 Internal Server Error

Something went wrong on MoreVoice's side. Retry with the same Idempotency-Key. Returns `ErrorEnvelope`.

## Code samples

**TypeScript**

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const flowValidation = await mv.flows.validate({
	graph: {
		kind: "voice",
		nodes: [
			{
				key: "start",
				transitions: [
					{
						condition: {
							kind: "always",
						},
						next: null,
					},
				],
				type: "start",
			},
		],
	},
});
console.log(flowValidation);
```

**Python**

```python
from morevoice import MoreVoice

client = MoreVoice()  # MOREVOICE_API_KEY from the environment

flow_validation = client.flows.validate({
    "graph": {
        "kind": "voice",
        "nodes": [
            {
                "key": "start",
                "transitions": [
                    {
                        "condition": {
                            "kind": "always",
                        },
                        "next": None,
                    },
                ],
                "type": "start",
            },
        ],
    },
})
print(flow_validation)
```

**cURL**

```sh
curl -X POST https://api.morevoice.ai/v1/flows/validate \
  -H "Authorization: Bearer $MOREVOICE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
  "graph": {
    "kind": "voice",
    "nodes": [
      {
        "key": "start",
        "transitions": [
          {
            "condition": {
              "kind": "always"
            },
            "next": null
          }
        ],
        "type": "start"
      }
    ]
  }
}'
```
