# Restore environment unified model version

> Source: https://truto.one/docs/api-reference/admin/installed-unified-models/restore-version/

`POST /environment-unified-model/{id}/versions/{version}/restore`

Resource: **Installed unified models**

Saves an older version's content as a new version. History is never rewound: restoring version 3 of a environment unified model at version 7 creates version 8, recorded with `source: restore` and `restored_from_version: 3`.

The save goes through `PATCH /environment-unified-model/{id}` as the caller, so it has the same permission checks, validation, webhooks and response as any other save. A refusal from that route is returned as is.

Versions hold no secrets, and a restore keeps the secrets stored today. A `*_secret` environment variable that is no longer stored is left out. A version whose credentials (a client ID, a signing key ID, or a token URL) differ from today's is refused with `400`, because today's secret would be paired with them. So is a version that has no value for a field a save cannot clear.

## Path parameters

- **`id`** _(string, required)_
  The object's ID.
- **`version`** _(integer, required)_

## Request body

- **`change_message`** _(string)_
  Why the version is being restored. Recorded with the new version.
- **`expected_current_version`** _(integer)_
  The version the caller believes is current, as `current_version` in the listing. When the object has moved on since, the restore is refused with `409` and nothing is saved.

## Errors

| Status | Description |
| :----- | :---------- |
| `400` | The version matches the current configuration, so restoring it would change nothing; its credentials differ from today's; it has no value for a field a save cannot clear; or the body is invalid. Also any refusal from the `PATCH` route. |
| `404` | No such environment unified model or version, or the caller cannot edit the environment unified model. |
| `409` | `expected_current_version` is not the environment unified model's current version: it changed since the caller read its history. |

## Code examples

### curl

```bash
curl -X POST 'https://api.truto.one/environment-unified-model/{id}/versions/{version}/restore' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "change_message": "your_change_message",
  "expected_current_version": 0
}'
```

### JavaScript

```javascript
const body = {
  "change_message": "your_change_message",
  "expected_current_version": 0
};

const response = await fetch('https://api.truto.one/environment-unified-model/{id}/versions/{version}/restore', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <your_api_token>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(body),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

url = "https://api.truto.one/environment-unified-model/{id}/versions/{version}/restore"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}
payload = {
    "change_message": "your_change_message",
    "expected_current_version": 0
}

response = requests.post(url, headers=headers, params=params, json=payload)
print(response.json())
```
