> ## Documentation Index
> Fetch the complete documentation index at: https://buttercms.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# API error codes

> A detailed reference for all possible ButterCMS API error codes and how to resolve them.

## HTTP status codes overview

| Status Code | Category | Description |
| - | - | - |
| `200 OK` | Success | Request succeeded, data returned |
| `202 Accepted` | Success | Write request accepted for processing |
| `400 Bad Request` | Client Error | Invalid request parameters |
| `401 Unauthorized` | Client Error | Authentication failed |
| `403 Forbidden` | Client Error | Access denied or resource conflict |
| `404 Not Found` | Client Error | Resource doesn't exist |
| `405 Method Not Allowed` | Client Error | HTTP method isn't supported on this endpoint |
| `429 Too Many Requests` | Client Error | Monthly API call limit exceeded (Free/Trial) |
| `500 Internal Server Error` | Server Error | Server-side issue |

***

## Authentication errors (401)

### Missing API token

```json theme={null}
{
  "detail": "Authentication credentials were not provided"
}
```

**Cause:** No API token was included in the request.

**Solution:** Include your API token either as:

* Query parameter: `?auth_token=YOUR_TOKEN`
* Authorization header: `Authorization: Token YOUR_TOKEN`

### Invalid API token

```json theme={null}
{
  "detail": "Invalid token"
}
```

**Cause:** The provided API token is incorrect or has been revoked.

**Solution:**

1. Go to Settings > General in your dashboard
2. Copy the correct Read API Token from the API Tokens section
3. Ensure there are no extra spaces or characters

### Write token required (403 Forbidden)

```json theme={null}
{
  "detail": "Your API token does not allow writes."
}
```

**Cause:** Attempting to create/update content with a Read API token. The token still authenticates successfully, so this returns 403 Forbidden rather than 401.

**Solution:** Write API access is a paid add-on for Advanced and Professional plans. Purchase it from the Billing page in your dashboard; the Write API Token activates automatically. On a Basic plan, upgrade first or [contact support](https://buttercms.com/docs/support/contact-status/contact-support.md).

***

## Bad request errors (400)

### Invalid query parameters

```json theme={null}
{
  "detail": "levels query parameter should be an integer between 1 and 5 (inclusive)"
}
```

**Cause:** Query parameter value is out of valid range or wrong type.

**Solution:** Check the API documentation for valid parameter values:

* `levels`: Integer 1-5
* `page`: Positive integer
* `page_size`: Integer 1-100

### Invalid locale parameter

The exact message depends on the endpoint:

```json theme={null}
{
  "locale": "The passed locale isn't configured on this account."
}
```

**Cause:** The specified locale doesn't exist or is not enabled on your account.

**Solution:**

1. Go to Settings > Localization in your dashboard
2. Verify the locale slug matches your API request
3. Locale slugs are typically lowercase (e.g., `en`, `es`, `fr-ca`)

### Invalid search parameters

```json theme={null}
{
  "query": ["Ensure this field has no more than 100 characters."]
}
```

**Cause:** Search query exceeds the maximum length of 100 characters.

**Solution:** Ensure search queries:

* Don't exceed 100 characters
* Are URL-encoded if containing special characters

### Invalid field filter (404 on Pages, 403 on Collections)

Filtering by a field uses dot notation, e.g. `fields.hero.title=value`. On Pages, an invalid filter returns a 404:

```json theme={null}
{
  "detail": "hero_image is not a valid field to filter by."
}
```

Omitting the dot returns:

```json theme={null}
{
  "detail": "fields is not a valid filter. Format is \"fields.field_id\""
}
```

On Collections, an invalid filter key returns a 403 instead:

```json theme={null}
{
  "detail": "Invalid filter key hero_image"
}
```

**Cause:** The field name after `fields.` doesn't exist in your content schema.

**Solution:** Check that:

* Field names match your content schema exactly
* You're using dot notation: `fields.hero.title`

***

## Forbidden errors (403)

### Multiple pages found

```json theme={null}
{
  "detail": "Multiple pages found with slug \"homepage\". Either pass in page_type or ensure only one page has this slug."
}
```

**Cause:** When using `page_type=*`, multiple pages share the same slug.

**Solution:**

1. Specify a page type instead of `*`: `/pages/landing_page/homepage`
2. Or ensure slugs are unique across all page types

### Access Denied

```json theme={null}
{
  "detail": "You do not have permission to perform this action"
}
```

**Cause:** Your account or API token doesn't have access to this resource.

**Solution:**

* Verify you're using the correct account's API token
* Check if your plan includes access to this feature
* [Contact support](https://buttercms.com/docs/support/contact-status/contact-support.md) if you believe this is an error

***

## Not found errors (404)

### Page not found

```json theme={null}
{
  "detail": "Page not found."
}
```

**Cause:** No page exists with the specified page type and slug.

**Solution:**

1. Verify the page is published (not draft)
2. Check the slug matches exactly (case-sensitive)
3. Confirm the page type key is correct
4. Verify the page exists in the dashboard

Posts and Collections return the generic `{"detail": "Not found."}` instead, so you can't tell those two apart by message text. Check the URL path you called.

### Collection not found

```json theme={null}
{
  "detail": "Not found."
}
```

**Cause:** The collection key, or the item ID within it, doesn't exist.

**Solution:**

1. Check the collection key in Content Types > Collections
2. Collection keys may contain letters, numbers, hyphens, and underscores
3. Keys are case-sensitive

### Blog Post not found

```json theme={null}
{
  "detail": "Not found."
}
```

**Cause:** No blog post exists with the specified slug.

**Solution:**

1. Verify the post is published
2. Check the slug is correct
3. Ensure you're not including `/blog/` prefix in the slug

***

## Method not allowed errors (405)

### Unsupported HTTP method

```json theme={null}
{
  "detail": "Method \"DELETE\" not allowed."
}
```

**Cause:** The HTTP method you used isn't supported on this endpoint, for example sending `DELETE` to a Pages or Collections endpoint, neither of which supports deleting via the API.

**Solution:** Check the API reference for the methods an endpoint supports.

***

## Rate limit errors (429)

### Too Many Requests

```json theme={null}
{
  "detail": "API Calls limit reached."
}
```

**Cause:** A Free or Trial account exceeded its monthly API call limit and has been temporarily blocked.

**Solution:**

1. **Check usage:** Review API calls on the Home dashboard Usage card or the Analytics page
2. **Reduce calls:** Cache responses and avoid polling
3. **Wait for reset:** The block lifts at the start of the next UTC calendar month
4. **Upgrade if needed:** Paid plans are not blocked for monthly API overages

**Rate Limit Response Headers:**

| Header | Description |
| - | - |
| `Retry-After` | Seconds to wait before retrying (provided by API when rate limited) |

> [!NOTE]
>
> When you exceed your plan's monthly API call limit, the `Retry-After` value indicates the seconds remaining until the end of the current billing month when your limit resets.

**Retry Logic Example:**

```javascript theme={null}
async function fetchWithRetry(url, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      const response = await fetch(url);
      if (response.status === 429) {
        const retryAfter = response.headers.get('Retry-After') || 60;
        console.log(`API limit reached. Retrying in ${retryAfter}s...`);
        await new Promise(r => setTimeout(r, retryAfter * 1000));
        continue;
      }
      return response.json();
    } catch (error) {
      if (i === maxRetries - 1) throw error;
    }
  }
}
```

***

## Validation Errors

### Content validation failed

For blog posts, each invalid field is reported under its own key (there's no `fields` wrapper):

```json theme={null}
{
  "title": ["This field is required."],
  "slug": ["The slug 'my-post' is not unique!"]
}
```

Pages don't have a top-level `title` field, so their validation errors are reported under the page type's own field keys instead.

**Cause:** Content being created/updated fails validation rules.

**Solution:** Check each field mentioned in the error:

* Ensure required fields are provided
* Verify slugs are unique
* Check field values meet validation rules (min/max length, format)

### Schema Mismatch

On **Pages**, submitting a field key that isn't defined in the page type's schema is dropped without an error.

On **Collections**, the same situation returns a 400:

```json theme={null}
["Unknown fields: hero_image"]
```

**Cause:** Trying to set a field that doesn't exist in the content schema.

**Solution:**

1. Check the page type or collection schema in Content Types
2. Ensure field names match exactly
3. For Collections, remove any fields not defined in the schema

***

## Server errors (500)

### Internal Server Error

An unhandled 500 on the API returns an HTML error page, not a JSON body, so don't try to parse `response.json()` for a 500.

**Cause:** An unexpected error on ButterCMS servers.

**Solution:**

1. Wait a few minutes and retry
2. Check the [API Status Page](https://status.buttercms.com)
3. If persistent, [contact support](https://buttercms.com/docs/support/contact-status/contact-support.md) with:
   * The exact endpoint you're calling
   * Request parameters
   * Timestamp of the error

***

## Error handling best practices

### JavaScript/TypeScript

```javascript theme={null}
async function safeFetch(fetchFn) {
  try {
    const response = await fetchFn();
    return { data: response.data, error: null };
  } catch (error) {
    const status = error.response?.status;
    const detail = error.response?.data?.detail;

    console.error(`ButterCMS Error [${status}]:`, detail);

    // Handle specific errors
    switch (status) {
      case 401:
        return { data: null, error: 'Authentication failed. Check your API token.' };
      case 404:
        return { data: null, error: 'Content not found.' };
      case 429:
        return { data: null, error: 'API limit reached. Please wait for the monthly reset.' };
      default:
        return { data: null, error: detail || 'An unexpected error occurred.' };
    }
  }
}
```

### Python

```python theme={null}
from butter_cms import ButterCMS
from requests.exceptions import HTTPError

client = ButterCMS('your-api-token')

try:
    page = client.pages.get('landing-page', 'homepage')
except HTTPError as e:
    # The SDK raises HTTPError(response.status_code) without attaching the
    # response, so only the status code is available here, not the body.
    status_code = e.args[0]
    if status_code == 401:
        print("Authentication failed. Check your API token.")
    elif status_code == 404:
        print("Page not found.")
    elif status_code == 429:
        print("API limit reached. Please wait for the monthly reset.")
    else:
        print(f"Error {status_code}")
```

***

## Quick reference table

| Error Code | Common Cause | Quick Fix |
| - | - | - |
| 401 | Missing/invalid token | Check Settings > General for the API Tokens section |
| 400 | Invalid parameters | Verify parameter values |
| 403 | Wrong page type, or Write token required | Specify exact page type, or purchase the Write API add-on |
| 404 | Content not published | Publish the content |
| 405 | Unsupported HTTP method | Check which methods the endpoint supports |
| 429 | Too many requests | Check usage, reduce calls, wait for monthly reset |
| 500 | Server issue | Wait and retry, check status |

***

## Related resources

> [card] [Common Errors](https://buttercms.com/docs/support/troubleshooting/common-errors-solutions.md)
>
> Step-by-step solutions for common issues

> [card] [Debugging Guide](https://buttercms.com/docs/support/troubleshooting/debugging-guide.md)
>
> How to debug your integration

> [card] [API Reference](https://buttercms.com/docs/api/overview.md)
>
> Full API documentation

> [card] [Contact Support](https://buttercms.com/docs/support/contact-status/contact-support.md)
>
> Get help from our team


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.