> ## Documentation Index
> Fetch the complete documentation index at: https://docs.goyappr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Restore Flow Version

> Replaces the agent's current `flow_config` with the contents of a previously-saved
version. The current state stays in version history (every save creates a snapshot,
deduped by content hash) so you can always restore back to it later.

Validation:
- Agent must be a flow agent (`type='flow'`).
- `version_id` must reference a row from `GET /agents/:id/flow/versions` for the
  same agent.

Required scope: `agents:update`.


Replaces a flow agent's current `flow_config` with the contents of a previously-saved version. Useful when a recent change broke the flow and you want to go back to a known-good state without manually rebuilding.

Required scope: `agents:update` (same as `PATCH /agents/:id`).

## How it works

Every save of a flow agent creates a row in `flow_versions` (deduped by content hash, so re-saving the same graph doesn't create redundant rows). Calling restore:

1. Looks up the row identified by `version_id`
2. Verifies the row belongs to this agent
3. Sets `agents.flow_config` to that row's stored content
4. Snapshots a new `flow_versions` row reflecting the restored state — but if the restored content equals the current head (you're restoring to where you already are), the unique constraint silently swallows it. No history pollution.

The current state stays in history before the restore happens, so you can always restore back to it later.

## Workflow

1. List versions: `GET /agents/:id/flow/versions` → pick a `version_id`
2. Restore: `POST /agents/:id/flow/restore` with `{ "version_id": "..." }`
3. Optionally verify: `GET /agents/:id` and inspect `flow_config`

## Constraints

* Agent must be a flow agent (`type='flow'`). Restoring on a prompt agent returns 400.
* `version_id` must belong to the agent named in the path. Cross-agent version ids return 404.

## Example request

```bash theme={null}
curl -X POST "https://api.goyappr.com/agents/AGENT_ID/flow/restore" \
  -H "Authorization: Bearer $YAPPR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"version_id": "9c1e9f04-2c5d-4a02-9c1a-1b5e9d1f0001"}'
```

## Example response

```json theme={null}
{
  "id": "AGENT_ID",
  "type": "flow",
  "name": "Booking flow",
  "flow_config": {
    "flow_config_version": "1",
    "nodes": [
      { "id": "start-1", "type": "start", "transitions": [{ "id": "to-ask-date", "next_step_id": "ask-date-1" }] }
    ]
  },
  "restored_from_version_id": "9c1e9f04-2c5d-4a02-9c1a-1b5e9d1f0001",
  "updated_at": "2026-05-11T12:34:56.789Z"
}
```

## Errors

| HTTP | Code | When                                                                           |
| ---- | ---- | ------------------------------------------------------------------------------ |
| 400  | —    | `version_id` missing or not a valid UUID.                                      |
| 400  | —    | Agent in the path is not a flow agent (`type` is `prompt`).                    |
| 404  | —    | Agent id does not exist (or is not visible to the calling company).            |
| 404  | —    | `version_id` does not exist, belongs to a different agent, or has been pruned. |


## OpenAPI

````yaml POST /agents/{id}/flow/restore
openapi: 3.1.0
info:
  title: Yappr API
  description: >
    Create and manage AI voice agents, purchase phone numbers, configure tools,
    and initiate calls — all via REST.
  version: 1.0.0
  contact:
    url: https://goyappr.com
servers:
  - url: https://api.goyappr.com
    description: Production
security:
  - apiKey: []
paths:
  /agents/{id}/flow/restore:
    parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
    post:
      tags:
        - Agents
      summary: Restore a previous flow version
      description: >
        Replaces the agent's current `flow_config` with the contents of a
        previously-saved

        version. The current state stays in version history (every save creates
        a snapshot,

        deduped by content hash) so you can always restore back to it later.


        Validation:

        - Agent must be a flow agent (`type='flow'`).

        - `version_id` must reference a row from `GET /agents/:id/flow/versions`
        for the
          same agent.

        Required scope: `agents:update`.
      operationId: restoreFlowVersion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - version_id
              properties:
                version_id:
                  type: string
                  format: uuid
                  description: Id from `GET /agents/:id/flow/versions[].id`.
      responses:
        '200':
          description: >-
            Restored. Returns the updated agent (same shape as `PATCH
            /agents/:id`).
        '400':
          description: Invalid body, or agent is not a flow agent.
        '404':
          description: >-
            Agent or version not found (or version doesn't belong to this
            agent).
components:
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        Your Yappr API key (e.g. `ypr_live_...`). Generate one in the dashboard
        under **Settings → API Keys**.

````