# Roll back to a previous deployment

> Re-deploy a previous version by copying its source, dependencies, and runtime pin onto the function's draft, then deploying. Returns immediately with a deployment ID — poll GET /v1/functions/deployments/{deploymentId} until status is active or failed. Secrets are not rolled back.

`POST https://api.zavu.dev/v1/functions/{functionId}/rollback`

Re-deploy a previous version by copying its source, dependencies, and runtime pin onto the function's draft, then deploying. Returns immediately with a deployment ID — poll GET /v1/functions/deployments/{deploymentId} until status is active or failed. Secrets are not rolled back.

## Parameters

- `functionId` (path, string, required): Zavu Function ID.

## Body

- `deploymentId` (string, required): ID of the deployment to roll back to.

## Responses

### 202

Rollback deployment queued.

- `deployment` (object, required)
  - `id` (string, required)
  - `functionId` (string, required)
  - `version` (integer, required): Monotonically increasing deployment version, starting at 1.
  - `status` (string, required): Stage of a function deployment. One of: `pending`, `bundling`, `uploading`, `publishing`, `active`, `failed`, `superseded`.
  - `sourceCodeBytes` (integer, nullable): Total size of the deployed source tree in bytes.
  - `bundleBytes` (integer, nullable): Size of the built bundle in bytes. Null until the build finishes.
  - `errorMessage` (string, nullable): Failure reason when status is 'failed'.
  - `buildLogs` (string, nullable): What the build printed: dependency installation, the bundler's output, and the compiler's message when it failed. Returned when fetching a single deployment, omitted from the list. Read this first when a deploy fails — `errorMessage` is often the outer wrapper's summary, and the line that names the broken import or the syntax error is here.
  - `deployedAt` (string<date-time>, nullable)
  - `createdAt` (string<date-time>, required)
- `rolledBackToVersion` (integer)
- `previousDraft` (object, nullable): The draft that was replaced, so a UI can offer to restore it.

### 400

Invalid request or function in a non-deployable state.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 401

Unauthorized.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

### 404

Function or deployment not found.

- `code` (string, required)
- `message` (string, required)
- `details` (object)

## Example

```bash
curl -X POST "https://api.zavu.dev/v1/functions/function_abc123/rollback" \
  -H "Authorization: Bearer $ZAVUDEV_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "deploymentId": "fnd_abc123"
}'
```

```typescript
import Zavudev from "@zavudev/sdk";

const zavu = new Zavudev({ apiKey: process.env.ZAVUDEV_API_KEY });

const result = await zavu.functions.rollbackDeployment("function_abc123", {
  deploymentId: "fnd_abc123",
});

console.log(result);
```
