# Versions

List and read versions, create a version from a batch of changes, publish, roll back and restore with the REST API.

## List versions

```http
GET /api/projects/:id/versions
```

Returns the version history, newest first: number, summary, author, time and when each was published.

## Get a version

```http
GET /api/projects/:id/versions/:n
GET /api/projects/:id/versions/latest
```

The version's functions (including `before` and `after`) and library modules with their code. `latest` is the newest version — the current draft.

## Create a version from a batch of changes

```http
POST /api/projects/:id/versions
```

Applies several changes at once and creates **one** new draft version. Either every change applies or none does — if one fails, nothing is saved and the error names it (`Change 2 (delete_function orders): …`). Scope: `functions:write`.

```json
{
  "summary": "Orders API and nightly report",
  "changes": [
    { "op": "put_library", "name": "money", "code": "export const cents = (n) => Math.round(n * 100);" },
    { "op": "put_function", "name": "orders", "method": "POST", "code": "export async function handler(req) { … }", "visibility": "private" },
    { "op": "put_function", "name": "report", "http": false, "code": "export async function handler() { … }", "schedule": { "cron": "0 6 * * *", "timezone": "UTC" } },
    { "op": "put_function", "name": "before", "code": "export async function handler(req) { … }" },
    { "op": "delete_function", "name": "legacy-orders" }
  ]
}
```

| `op` | Fields | Does |
| --- | --- | --- |
| `put_function` | `name`, `code`, and any [function field](/api/rest-functions#create-a-function): `http`, `method`, `visibility`, `mcp`, `beforeAfter`, `schedule`, `cache`, `language`, `description`, `inputSchema`, `outputSchema` | Creates the function, or updates the one with that name |
| `delete_function` | `name` | Deletes a function |
| `put_library` | `name`, `code`, `language`, `description` | Adds or replaces a library module |
| `delete_library` | `name` | Deletes a library module |

When updating, fields you leave out keep their current values; `code` is required only when creating. Up to 100 changes per call. `summary` (up to 200 characters) is the version's description; without it, Wisp lists the changes.

Returns `{ "changed": true, "version": 13, "summary": "…", "deploy": { … } }`, or `{ "changed": false }` when nothing differed. The new version is a draft: test it, then [publish](#publish).

## Publish

```http
POST /api/projects/:id/publish
```

Body: `{ "version": 12 }` to publish (roll back to) a specific version, or `{}` for the current draft. Scope: `projects:deploy`.

```bash
curl -X POST https://wispfn.com/api/projects/$PROJECT/publish \
  -H "Authorization: Bearer $WISP_API_KEY" -H "content-type: application/json" -d '{}'
```

## Restore

```http
POST /api/projects/:id/versions/:n/restore
```

Makes the draft match version `n` by creating a new version. Doesn't publish. Scope: `functions:write`.
