# Capture a website

Saves a web page (url) or your own HTML (html) as PDF, PNG, JPG or WEBP. The settings are the same as for the capture-website task of POST /v2/jobs, including headers and cookies for pages behind a login. Answers with 202 right away; ?wait=true (or a number of seconds, at most 30) waits for the result. Loading may take 30 seconds and 50 MB at most; a full-page image is cut at 20000 pixels height. At most 30 captures per minute and key (5 without credits). Costs 1 credit.

`POST https://api.switchfile.io/v1/captures`

Needs an API key: `Authorization: Bearer YOUR_API_KEY`. See [Authentication](https://switchfile.io/docs/authentication).

## Example

cURL:

```bash
curl "https://api.switchfile.io/v1/captures?wait=true" \
  -H "Authorization: Bearer $SWITCHFILE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/pricing",
    "output_format": "pdf",
    "options": {
      "page_format": "a4"
    }
  }'
```

Node.js:

```js
const res = await fetch("https://api.switchfile.io/v1/captures?wait=true", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SWITCHFILE_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    url: "https://example.com/pricing",
    output_format: "pdf",
    options: {
      page_format: "a4"
    }
  }),
});
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
console.log(await res.json());
```

PHP:

```php
<?php
$ch = curl_init('https://api.switchfile.io/v1/captures?wait=true');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode([
        'url' => 'https://example.com/pricing',
        'output_format' => 'pdf',
        'options' => [
            'page_format' => 'a4',
        ],
    ]),
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('SWITCHFILE_API_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_RETURNTRANSFER => true,
]);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

if ($status >= 400) {
    throw new RuntimeException("HTTP $status: $response");
}
print_r(json_decode($response, true));
```

Python:

```python
import os
import requests

res = requests.post(
    "https://api.switchfile.io/v1/captures?wait=true",
    headers={"Authorization": f"Bearer {os.environ['SWITCHFILE_API_KEY']}"},
    json={
        "url": "https://example.com/pricing",
        "output_format": "pdf",
        "options": {
            "page_format": "a4",
        },
    },
)
res.raise_for_status()
print(res.json())
```

## Parameters

### Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `wait` | string \| number | no | true or a number of seconds: wait until the capture is done, at most 30 seconds (one of "true"; example: true) |

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string | no | 1 to 255 visible ASCII characters, for example a UUID. Send the request again with the same key after a timeout: nothing is created twice. Kept for 24 hours. (example: 6f1c2b8e-1d8e-4c55-9f0e-3f3f0b0a8f21) |
| `X-End-User` | string | no | Service keys only: an ID for the visitor you act for (1 to 128 characters: letters, digits and . _ : @ -). Quotas and rate limits then count per visitor. |
| `X-End-User-Ip` | string | no | Required with X-End-User: the IP address of the visitor. |

## Request body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `filename` | string | no | File name of the result; the extension is added if missing (1 to 255 characters) |
| `html` | string | no | An HTML document to capture instead of a web page, at most 1 MB. Use absolute URLs for images and styles, or data URLs (1 to 1048576 characters) |
| `options` | map of string \| number \| boolean \| null \| map of string \| map of string[] | no | Settings as for the capture-website task of POST /v2/jobs, for example { "device": "mobile" }, { "page_format": "a4" } or { "cookies": [{ "name": "session", "value": "…" }] }. Unknown settings are rejected. headers and cookies are stored encrypted and shown as [redacted] (at most 50 entries; keys match ^[a-z][a-z0-9_]{0,63}$) |
| `output_format` | string | yes | Format of the result. A pdf keeps the text selectable; png, jpg and webp give one image (one of "pdf", "png", "jpg", "webp") |
| `url` | string | no | Address of the public web page (http or https, ports 80 and 443). Send url or html (at most 4096 characters; matches ^https?://) |

## Responses

### 200: Done within wait

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `created_at` | string | yes | ISO 8601 timestamp, for example 2026-11-06T18:00:00+00:00 |
| `credits` | string (integer) \| integer | yes | Credits used, set once the capture is done |
| `error` | object \| null | yes |  |
| `error.code` | string | yes |  |
| `error.message` | string | yes |  |
| `expires_at` | string \| null | yes | The result is deleted at this time |
| `finished_at` | string \| null | yes | ISO 8601 timestamp, for example 2026-11-06T18:00:00+00:00 |
| `id` | string (uuid) | yes |  |
| `links` | object | yes |  |
| `links.self` | string | yes |  |
| `object` | string | yes | (one of "website_capture") |
| `options` | map of any | yes | The settings as sent; headers and cookies as [redacted] (keys match ^(.*)$) |
| `output_format` | string | yes | (one of "pdf", "png", "jpg", "webp") |
| `result` | object \| null | yes |  |
| `result.file` | object | yes |  |
| `result.file.filename` | string | yes |  |
| `result.file.size` | string (integer) \| integer | yes | (at least 0) |
| `result.file.url` | string | yes | Signed download URL, valid until expires_at |
| `result.height` | string (integer) \| integer | yes | Image height in pixels (png, jpg, webp) |
| `result.notes` | string[] | yes | Notes, for example when a very tall page was cut at the height limit |
| `result.pages` | string (integer) \| integer | yes | Number of pages (pdf) |
| `result.title` | string \| null | yes | Title of the page |
| `result.width` | string (integer) \| integer | yes | Image width in pixels (png, jpg, webp) |
| `status` | string | yes | (one of "queued", "processing", "finished", "failed") |
| `url` | string \| null | yes | The address as sent; null when html was sent |

Example (application/json):

```json
{
  "id": "d4b7e2a9-6c1f-4e83-a05d-3f9b8c2e1a76",
  "object": "website_capture",
  "status": "finished",
  "url": "https://example.com/pricing",
  "output_format": "pdf",
  "options": {
    "page_format": "a4"
  },
  "result": {
    "file": {
      "filename": "pricing.pdf",
      "size": 184213,
      "url": "https://api.switchfile.io/files/2a6f8e1c-4b3d-4e7a-9c5f-8d1b0e2a4c67/pricing.pdf?expires=1762538401&signature=3f9c2a7d41e8b6c05d1f9e2a7b4c8d3e6f0a1b2c3d4e5f60718293a4b5c6d7e8"
    },
    "width": null,
    "height": null,
    "pages": 3,
    "title": "Pricing",
    "notes": []
  },
  "error": null,
  "credits": 1,
  "created_at": "2026-11-06T18:00:00+00:00",
  "finished_at": "2026-11-06T18:00:02+00:00",
  "expires_at": "2026-11-07T18:00:02+00:00",
  "links": {
    "self": "https://api.switchfile.io/v1/captures/d4b7e2a9-6c1f-4e83-a05d-3f9b8c2e1a76"
  }
}
```

### 202: Created, still running. Poll links.self with ?wait=true

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `created_at` | string | yes | ISO 8601 timestamp, for example 2026-11-06T18:00:00+00:00 |
| `credits` | string (integer) \| integer | yes | Credits used, set once the capture is done |
| `error` | object \| null | yes |  |
| `error.code` | string | yes |  |
| `error.message` | string | yes |  |
| `expires_at` | string \| null | yes | The result is deleted at this time |
| `finished_at` | string \| null | yes | ISO 8601 timestamp, for example 2026-11-06T18:00:00+00:00 |
| `id` | string (uuid) | yes |  |
| `links` | object | yes |  |
| `links.self` | string | yes |  |
| `object` | string | yes | (one of "website_capture") |
| `options` | map of any | yes | The settings as sent; headers and cookies as [redacted] (keys match ^(.*)$) |
| `output_format` | string | yes | (one of "pdf", "png", "jpg", "webp") |
| `result` | object \| null | yes |  |
| `result.file` | object | yes |  |
| `result.file.filename` | string | yes |  |
| `result.file.size` | string (integer) \| integer | yes | (at least 0) |
| `result.file.url` | string | yes | Signed download URL, valid until expires_at |
| `result.height` | string (integer) \| integer | yes | Image height in pixels (png, jpg, webp) |
| `result.notes` | string[] | yes | Notes, for example when a very tall page was cut at the height limit |
| `result.pages` | string (integer) \| integer | yes | Number of pages (pdf) |
| `result.title` | string \| null | yes | Title of the page |
| `result.width` | string (integer) \| integer | yes | Image width in pixels (png, jpg, webp) |
| `status` | string | yes | (one of "queued", "processing", "finished", "failed") |
| `url` | string \| null | yes | The address as sent; null when html was sent |

Example (application/json):

```json
{
  "id": "d4b7e2a9-6c1f-4e83-a05d-3f9b8c2e1a76",
  "object": "website_capture",
  "status": "queued",
  "url": "https://example.com/pricing",
  "output_format": "pdf",
  "options": {
    "page_format": "a4"
  },
  "result": null,
  "error": null,
  "credits": null,
  "created_at": "2026-11-06T18:00:00+00:00",
  "finished_at": null,
  "expires_at": null,
  "links": {
    "self": "https://api.switchfile.io/v1/captures/d4b7e2a9-6c1f-4e83-a05d-3f9b8c2e1a76"
  }
}
```

### 401: The API key is missing or not valid (`UNAUTHENTICATED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-unauthenticated",
  "title": "Unauthenticated",
  "status": 401,
  "code": "UNAUTHENTICATED",
  "detail": "Missing or invalid API key. Send it as Authorization: Bearer <key>. No key yet? Follow get_a_key.",
  "get_a_key": {
    "summary": "No API key yet? Get one with two requests, without a browser.",
    "steps": [
      {
        "method": "POST",
        "url": "https://api.switchfile.io/v1/signup",
        "body": {
          "email": "you@example.com",
          "accept_terms": true
        },
        "result": "We email a code with 8 digits to the address."
      },
      {
        "method": "POST",
        "url": "https://api.switchfile.io/v1/signup/verify",
        "body": {
          "email": "you@example.com",
          "code": "12345678",
          "accept_terms": true
        },
        "result": "Your API key, shown once. Send it as Authorization: Bearer <key>."
      }
    ],
    "terms_url": "https://switchfile.io/terms",
    "privacy_url": "https://switchfile.io/privacy",
    "docs_url": "https://switchfile.io/docs/authentication#get-an-api-key-without-a-browser"
  }
}
```

### 402: Today's free quota is used up and there are not enough credits (`CREDITS_EXCEEDED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-credits-exceeded",
  "title": "Credits exceeded",
  "status": 402,
  "code": "CREDITS_EXCEEDED",
  "detail": "Today's free quota is used up and there are not enough credits left."
}
```

### 403: X-End-User was sent with a key that is not a service key, or the account converts without storage (no_store, STORAGE_DISABLED) (`END_USER_NOT_ALLOWED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-end-user-not-allowed",
  "title": "End user not allowed",
  "status": 403,
  "code": "END_USER_NOT_ALLOWED",
  "detail": "The X-End-User header is only allowed with a service key."
}
```

### 404: Does not exist for this account (`NOT_FOUND`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-not-found",
  "title": "Not found",
  "status": 404,
  "code": "NOT_FOUND",
  "detail": "Conversion not found."
}
```

### 409: The request with this Idempotency-Key is still running (`IDEMPOTENCY_KEY_IN_USE`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-idempotency-key-in-use",
  "title": "Idempotency key in use",
  "status": 409,
  "code": "IDEMPOTENCY_KEY_IN_USE",
  "detail": "A request with this Idempotency-Key is still running."
}
```

### 415: Send JSON or multipart/form-data (`UNSUPPORTED_MEDIA_TYPE`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-unsupported-media-type",
  "title": "Unsupported media type",
  "status": 415,
  "code": "UNSUPPORTED_MEDIA_TYPE",
  "detail": "Send the request as application/json."
}
```

### 422: Invalid data, a URL that is not public, or an option that is not supported (`INVALID_DATA`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-invalid-data",
  "title": "Invalid data",
  "status": 422,
  "code": "INVALID_DATA",
  "detail": "The request contains invalid data.",
  "errors": {
    "options.cookies": [
      "Cookies are not supported. Only pages that are public without a login can be captured."
    ]
  }
}
```

### 429: Too many requests, or the daily quota for captures is used up (`RATE_LIMIT_EXCEEDED`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-rate-limit-exceeded",
  "title": "Rate limit exceeded",
  "status": 429,
  "code": "RATE_LIMIT_EXCEEDED",
  "detail": "Too many requests. Try again in 12 seconds."
}
```

### 503: Website capture is switched off on this server (`ENGINE_UNAVAILABLE`)

Example (application/problem+json):

```json
{
  "type": "https://switchfile.io/docs/api/v1#errors-engine-unavailable",
  "title": "Engine unavailable",
  "status": 503,
  "code": "ENGINE_UNAVAILABLE",
  "detail": "Website capture is not available on this server."
}
```

Error bodies and codes are explained in [Errors](https://switchfile.io/docs/errors).
