> ## 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 workflow version

> Make an earlier version's workflow live again, as a new version.

Requires `agents:update`. Restoring publishes a copy of an earlier version's
workflow as a **new** version. It rolls forward: version numbers only go up, the
version you restored from stays in the history, and callers reach the new version
on their next call. A call already in progress keeps the version it started on.

**id** `string` *required*

Local agent UUID.

**version\_id** `string`

The `id` of the version to restore, from [List workflow versions](https://docs.goyappr.com/api-reference/workflows/versions.md). Send exactly one of `version_id` and `version`.

**version** `integer`

The number of the version to restore, instead of its id.

**expected\_version** `integer`

The saved draft's version you last read. When the draft has moved since, the answer is `409 WORKFLOW_CONFLICT` and nothing is published. Optional.

**discard\_draft** `boolean` (default: false)

`true` replaces a saved draft that holds unpublished changes with the restored workflow. `false` refuses instead of losing them.

```bash theme={null}
curl -X POST 'https://api.goyappr.com/agents/AGENT_ID/workflow/restore' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'x-company-id: COMPANY_ID' \
  -H 'Content-Type: application/json' \
  -d '{"version_id":"VERSION_ID","expected_version":7,"discard_draft":false}'
```

`201` returns the new `revision` (`id`, `version`, `content_hash`,
`published_at`, `environment`), `execution_version`, `restored_from` (`id` and
`version` of the copy's source), `draft_version`, `discarded_draft`, and
`settings_updated_at`, the same token [Publish workflow](https://docs.goyappr.com/api-reference/workflows/publish.md#publishing-moves-the-settings-token)
returns. Send it as `expected_updated_at` on your next agent `PATCH`.

## What a restore does and does not promise

* **It is a new version.** The restored workflow is published again, so the
  list shows a new row with `source: "restore"` and `restored_from_version`.
* **It is not guaranteed to be byte-identical.** The old document is checked and
  built again with today's rules. For most versions the result matches; an agent
  whose version was rebuilt on 2026-11-12 can differ from it in compiled details
  (the document text you read with
  [Get workflow version](https://docs.goyappr.com/api-reference/workflows/version.md) is what is restored).
* **It can be refused.** If the old document no longer passes today's checks
  (a tool in it was archived, an app account was disconnected) the answer is
  `422 WORKFLOW_REFERENCE_INVALID` or `WORKFLOW_VALIDATION_FAILED` with
  `issues[]`, nothing is published, and your draft is put back as it was.
* **It is not idempotent.** Every successful call makes one more version. If you
  never received the answer, read the version list before sending it again.

## Refusals

| Status | Code | Meaning |
| - | - | - |
| 400 | `WORKFLOW_REQUEST_INVALID` | Both or neither of `version_id` and `version`, a malformed value, another field, or a query parameter. `issues[]` names each by path. |
| 404 | `WORKFLOW_NOT_FOUND` | No version of this agent has that id or number. |
| 409 | `WORKFLOW_CONFLICT` | `expected_version` is not the saved draft's version now. `current_version` names it. |
| 409 | `WORKFLOW_DRAFT_HAS_UNPUBLISHED_CHANGES` | The saved draft differs from the published version. The body also carries `reason: "draft_has_unpublished_changes"`. Publish or discard the draft, or send `discard_draft: true`. |
| 409 | `WORKFLOW_VERSION_IS_CURRENT` | That version is the one callers reach now; there is nothing to restore. |
| 422 | `WORKFLOW_REFERENCE_INVALID`, `WORKFLOW_VALIDATION_FAILED` | The old document no longer passes today's checks. |
| 503 | `WORKFLOW_COMPILER_UNAVAILABLE` | Nothing was published. Read the version list before retrying. |

```json theme={null}
{
  "error": "The saved draft has changes that are not published. Publish or discard them first, or restore with discard_draft set to true.",
  "code": "WORKFLOW_DRAFT_HAS_UNPUBLISHED_CHANGES",
  "reason": "draft_has_unpublished_changes"
}
```

To undo a [Teach run](https://docs.goyappr.com/api-reference/workflows/train.md), restore the run's
`base_revision`.


## OpenAPI

````yaml POST /agents/{id}/workflow/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}/workflow/restore:
    parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      - in: header
        name: x-company-id
        schema:
          type: string
          format: uuid
        description: >-
          Explicit active workspace. Optional; when sent it must be the API
          key's own workspace — any other value is refused with 403
          WORKSPACE_MISMATCH.
    post:
      tags:
        - Workflows
      summary: Restore an earlier workflow version
      description: >
        Requires agents:update. Makes an earlier version's workflow live again
        by publishing a copy of it as a NEW version (roll-forward): version
        numbers only go up, the version you restored from stays in the history,
        and callers reach the new version on their next call. A call already in
        progress keeps the version it started on. The copy is built again from
        the old document, so it is not guaranteed to be byte-identical to the
        old version: an agent whose version was rebuilt on 2026-11-12 can differ
        in compiled details, and the restore is refused when the old document no
        longer passes today's checks (for example a tool in it was archived).
        Name the version with exactly one of version_id or version. Not
        idempotent: each successful call creates one more version, so do not
        retry a request whose answer you did not receive without reading the
        version list first. Refused with 409
        WORKFLOW_DRAFT_HAS_UNPUBLISHED_CHANGES while the saved draft holds
        changes that are not published, unless discard_draft is true (the draft
        is then replaced by the restored workflow).
      operationId: restoreWorkflowVersion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WorkflowRestoreRequest'
      responses:
        '201':
          description: The restored workflow is live as a new version.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowRestoreResponse'
        '400':
          description: >-
            WORKFLOW_REQUEST_INVALID: both or neither of version_id and version,
            a malformed field, another field, or a query parameter. issues[]
            names each by path.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowError'
        '401':
          description: >-
            MISSING_KEY, INVALID_KEY or EXPIRED_KEY - the key was not accepted.
            A valid key without the scope this operation needs is 403
            INSUFFICIENT_SCOPE, naming the scope.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: >-
            WORKSPACE_MISMATCH — `x-company-id` named a workspace other than the
            one this API key belongs to.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: >-
            WORKFLOW_NOT_FOUND: the agent is unavailable in this company, or no
            version of this agent has that id or number.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowError'
        '409':
          description: >
            One of three refusals; nothing was published and the draft is
            untouched.

            `WORKFLOW_CONFLICT` — `expected_version` is not the saved draft's
            version now (`current_version` names it).

            `WORKFLOW_DRAFT_HAS_UNPUBLISHED_CHANGES` — the saved draft differs
            from the published version; the body carries `reason:
            "draft_has_unpublished_changes"`. Publish or discard the draft
            first, or send `discard_draft: true`.

            `WORKFLOW_VERSION_IS_CURRENT` — the named version is the one callers
            reach now; there is nothing to restore.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowError'
              examples:
                draftHasUnpublishedChanges:
                  summary: The draft holds changes that are not published
                  value:
                    error: >-
                      The saved draft has changes that are not published.
                      Publish or discard them first, or restore with
                      discard_draft set to true.
                    code: WORKFLOW_DRAFT_HAS_UNPUBLISHED_CHANGES
                    reason: draft_has_unpublished_changes
        '422':
          description: >-
            WORKFLOW_REFERENCE_INVALID or WORKFLOW_VALIDATION_FAILED: the old
            document no longer passes today's checks (an archived tool, a
            connection that moved), with issues[]. Nothing was published and the
            draft is put back as it was.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowError'
        '503':
          description: >-
            WORKFLOW_COMPILER_UNAVAILABLE: no version was published; read the
            version list before retrying.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    WorkflowRestoreRequest:
      type: object
      additionalProperties: false
      description: Name the version with exactly one of version_id and version.
      properties:
        version_id:
          type: string
          format: uuid
          description: >-
            The id of the version to restore, from GET
            /agents/{id}/workflow/versions.
        version:
          type: integer
          minimum: 1
          description: The number of the version to restore.
        expected_version:
          type: integer
          minimum: 1
          maximum: 9007199254740991
          description: >-
            The saved draft's version you last read. Refused with 409
            WORKFLOW_CONFLICT when the draft has moved since. Optional.
        discard_draft:
          type: boolean
          default: false
          description: >-
            True replaces a saved draft that holds unpublished changes with the
            restored workflow. False (default) refuses with 409
            WORKFLOW_DRAFT_HAS_UNPUBLISHED_CHANGES instead of losing them.
    WorkflowRestoreResponse:
      type: object
      required:
        - revision
        - execution_version
        - restored_from
        - draft_version
        - discarded_draft
      properties:
        revision:
          $ref: '#/components/schemas/WorkflowRevisionSummary'
        execution_version:
          const: workflow_v1
          readOnly: true
        restored_from:
          type: object
          required:
            - id
            - version
          properties:
            id:
              type: string
              format: uuid
            version:
              type: integer
              minimum: 1
        draft_version:
          type: integer
          minimum: 1
          description: The saved draft's version after the restore.
        discarded_draft:
          type: boolean
          description: True when unpublished draft changes were replaced.
        settings_updated_at:
          type: string
          format: date-time
          readOnly: true
          description: >-
            The agent settings token as of this restore, as POST
            /agents/{id}/workflow/publish answers it. Send it as
            expected_updated_at on your next PATCH /agents/{id}.
    WorkflowError:
      allOf:
        - $ref: '#/components/schemas/Error'
        - type: object
          required:
            - code
          properties:
            error:
              type: string
            code:
              type: string
            warnings:
              type: array
              description: >
                On WORKFLOW_VALIDATION_FAILED from Check or publish, the
                advisories beside the issues, in the shape of
                WorkflowValidation's warnings - strict_off_guidance when
                strict_mode is off, and every advisory about a binding or an
                input. The compiler's own graph advisories
                (during_output_advisory, sequence_branch_advisory,
                before_reference_missing_fallback, override_needs_strict,
                after_ending_coverage, after_any_end_waits,
                before_budget_inbound) arrive once the document compiles.
              items:
                type: object
                required:
                  - code
                  - message
                properties:
                  code:
                    type: string
                  message:
                    type: string
                  path:
                    type: string
                    maxLength: 1000
                  node_id:
                    type: string
                    maxLength: 64
                  label:
                    type: string
                    maxLength: 200
                    description: The step's label. Present only with node_id.
                  tool_name:
                    type: string
                    maxLength: 200
                  field:
                    type: string
                    maxLength: 200
            issues:
              type: array
              maxItems: 100
              items:
                type: object
                required:
                  - code
                  - path
                  - message
                properties:
                  code:
                    type: string
                    maxLength: 100
                  path:
                    type: string
                    maxLength: 1000
                  message:
                    type: string
                    maxLength: 2000
                  node_id:
                    type: string
                    maxLength: 64
                    description: >-
                      The step the issue belongs to - a conversation step, a
                      before-call step, a follow-up or a step inside a sequence,
                      by its `id`. An issue about a binding names the first step
                      that runs or offers it; absent only when no single step is
                      concerned (a binding no step uses, a schema).
                  label:
                    type: string
                    maxLength: 200
                    description: >-
                      That step's label, as the workflow document spells it - on
                      every code. Present only with `node_id`.
                  tool_name:
                    type: string
                    maxLength: 200
                    description: >-
                      On an issue about a binding, the name of the tool it runs.
                      `label` is never the tool's name.
                  field:
                    type: string
                    maxLength: 200
                    description: >-
                      On an issue about one input of a binding
                      (`/bindings/{n}/inputs/{field}`), that input's name.
    Error:
      type: object
      required:
        - error
        - code
      description: >
        Every error response - the secret-key API and the browser data plane
        alike - carries a

        human-readable `error` and a stable machine `code`, and a refusal that
        names what is

        wrong with the request carries `issues[]` too. Branch on `code`, never
        on the `error`

        text. A refusal that names nothing more specific carries the code its
        status means:

        `BAD_REQUEST` (400), `UNAUTHORIZED` (401, the browser data plane; the
        secret-key API

        answers `MISSING_KEY`, `INVALID_KEY` or `EXPIRED_KEY`), `BILLING_ERROR`
        (402),

        `FORBIDDEN` (403), `NOT_FOUND` (404), `METHOD_NOT_ALLOWED` (405),
        `CONFLICT` (409),

        `GONE` (410), `PAYLOAD_TOO_LARGE` (413), `UNSUPPORTED_MEDIA_TYPE` (415),

        `UNPROCESSABLE_REQUEST` (422), `RATE_LIMIT` (429), `INTERNAL_ERROR`
        (500),

        `UPSTREAM_ERROR` (502), `SERVICE_UNAVAILABLE` (503), `UPSTREAM_TIMEOUT`
        (504). Some

        refusals add members of their own beside these (a call request's
        `status`, a workflow's

        `current_version`); the operation says which.
      properties:
        error:
          type: string
          description: The refusal, in one sentence for a person. Its wording may change.
        code:
          type: string
          description: The stable code to branch on.
        issues:
          type: array
          description: >
            Each thing at fault, on a 400 or 422 that names them: every query
            parameter or body field, not just the first. `path` is the
            parameter's name or the field's location.
          items:
            type: object
            required:
              - code
              - message
            properties:
              code:
                type: string
                description: >-
                  query_param_unknown, query_param_repeated, query_param_blank,
                  query_param_invalid, field_unknown, field_required,
                  field_invalid, or the route's own word.
              path:
                type: string
              message:
                type: string
    WorkflowRevisionSummary:
      type: object
      required:
        - id
        - version
        - content_hash
        - published_at
      properties:
        id:
          type: string
          format: uuid
        version:
          type: integer
          minimum: 1
        content_hash:
          type: string
          pattern: ^[a-f0-9]{64}$
        published_at:
          type: string
          format: date-time
        environment:
          type: string
          enum:
            - local
            - testing
            - production
          readOnly: true
          description: >
            The deployment plane that compiled and stored this revision. Decided
            by the deployment, never sent by the caller; the hosted API stores
            as testing. A call loads only a version stored on the plane it runs
            on, and publishing and calling through the same API are the same
            plane. See the List workflow versions page.
  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**. No key is `401 MISSING_KEY`; a key that
        is not one of ours, or is revoked, is `401 INVALID_KEY`; an expired one
        is `401 EXPIRED_KEY`. A valid key without the scope an operation needs
        is `403 INSUFFICIENT_SCOPE` on every operation, and the message names
        the scope. Every response, a 401 included, carries X-RateLimit-Limit,
        X-RateLimit-Remaining and X-RateLimit-Reset: the budget is 60 requests a
        minute per API key. Every 429, whatever its code, carries Retry-After
        (whole seconds, never zero): the per-key budget's `RATE_LIMIT` asks for
        what is left of the minute, a route's daily cap (`RATE_LIMITED`) for the
        time until that cap resets. All four headers are listed in
        Access-Control-Expose-Headers, so a browser can read them. A path the
        API does not serve (an unknown sub-path, an id left empty) is `404
        ROUTE_NOT_FOUND`, and a method a served path does not take is `405
        METHOD_NOT_ALLOWED` with an `Allow` header; both are answered before any
        scope check, and nothing is read or changed. A trailing slash is ignored
        where it cannot be an id left empty (`POST /calls/` is `POST /calls`)
        and refused where it can (`GET /calls/`). A doubled slash inside a path
        is merged into one before the request reaches the API (`GET //calls` is
        `GET /calls`).

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.