
# Update a preview

Change a preview's visibility or password.

```sh
PATCH https://sitepaste.com/api/v1/public/sites/{siteId}/previews/{previewId}
```

Requires the `deploy` scope.

## Usage

```bash
curl -X PATCH "https://sitepaste.com/api/v1/public/sites/default/previews/pv7k3q9r2m4x" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "visibility": "password", "password": "reviewers-only" }'
```

## Authorizations

| Header | Type | Required | Description |
|--------|------|----------|-------------|
| Authorization | string | Yes | Bearer token (`Authorization: Bearer sp_...`). Created in the dashboard under Account > Tokens. See [authentication](/api/authentication). |

## Body

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| visibility | string | Yes | `public`, `password`, or `workspace`. Always required, so a password-only PATCH is refused with 422. |
| password | string | No | Sets the preview password, at most 72 bytes. Required when switching to `password` visibility unless a password is already set. Switching without one, or sending a longer one, is refused with 422, `code: validation_failed`, and `fields.password`. |

## Response

200 OK with the preview as it now stands, in the same shape as [read a preview](/api/previews/get-previews-previewid), `createdByName` included.

400 when `{previewId}` is malformed. 404 when it is well formed but names no preview on this site.

409 when the preview is not `building` or `ready`. A failed, promoted, or expired preview cannot be updated.

A token never receives an `authUrl`, even for `workspace` visibility. To fetch a preview's content back, create it `public` or with a password.