# Change document versioning state

Source: https://docs.orbiqhq.com/docs/api/v1/documents/id/versioning/patch

### PATCH /api/v1/documents/{id}/versioning

**Change document versioning state**

Enabling versioning requires a published base document. Otherwise, return
`409` without changing the document or its versions. Disabling versioning
remains available for unpublished base documents.

To disable versioning, the API uses the active published version as the
source, or the newest published version when no active published version
exists. It copies the source version fields and status into the base
document, then sets
`versioning` to `false`. A document without a source version changes only
the flag. This action does not delete, archive, deactivate, or otherwise
mutate retained versions.

While versioning is disabled, the default document read and `version=base`
both return base content. Retained versions do not control returned content,
even when `active_version` contains their UUID. Base changes continue through
`PATCH /api/v1/documents/{id}`.

To enable versioning, the API does not create a draft or mutate retained
versions. Normal promoted-content selection resumes and a retained active
published version can become effective again.

**Authentication:** Bearer token (`Authorization: Bearer <token>`)

**Path parameters:**

| Name | Type | Required | Description |
|---|---|---|---|
| `id` | string (uuid) | Yes | Document UUID |

**Request body** (`application/json`) - required:

- `versioning` (boolean, required)

Example (disable):

```json
{
  "versioning": false
}
```

Example (enable):

```json
{
  "versioning": true
}
```

**Responses:**

- `200` - Versioning state updated
  - `success` (boolean, required)
  - `data` (object, required)
    - `versioning` (boolean, required)

  Example (The active published source is materialized into base content; retained versions remain unchanged.):
  
  ```json
  {
  "success": true,
  "data": {
    "versioning": false
  }
}
  ```

  Example (Versioning resumes without creating a draft.):
  
  ```json
  {
  "success": true,
  "data": {
    "versioning": true
  }
}
  ```
- `400` - Invalid document UUID or request body
  - `error` (string, required)
- `401` - Authentication required
  - `error` (string, required)
- `403` - Not authorized for this document
  - `error` (string, required)
- `404` - Document not found
  - `error` (string, required)
- `409` - The base document is not published
  - `error` (string, required)

**Code samples:**

cURL:

```bash
curl -X PATCH "https://app.orbiqhq.com/api/v1/documents/550e8400-e29b-41d4-a716-446655440000/versioning" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"versioning":false}'
```

JavaScript (fetch):

```js
const response = await fetch(
  "https://app.orbiqhq.com/api/v1/documents/550e8400-e29b-41d4-a716-446655440000/versioning",
  {
    method: "PATCH",
    headers: { Authorization: `Bearer ${process.env.ACCESS_TOKEN}`, "Content-Type": "application/json" },
    body: JSON.stringify({ versioning: false }),
  }
);
if (!response.ok) throw new Error(await response.text());
const payload = await response.json();
```
