# API errors

Reference for Pristo API errors: the status codes and plain-text messages that 400, 401, 404 and 500 responses return, and how to fix each one.

This page lists every error that the Pristo API endpoints `POST /v1/events/send` and `POST /v1/links/generate/{prjId}` return, with the message in the body and the fix.

## How errors look

- Most `400` and `404` errors have a plain-text body, for example `contact is required`. It isn't JSON, so read it as text.
- `401`, `415`, some `400` and most `500` errors have a JSON problem body (`Content-Type: application/problem+json`) with `title` and `status`. A `500` may add a `detail` message.
- The API checks the request in this order: the path, the body, the API key, then the data. A request with several problems returns the first one only.

## Errors on both endpoints

| Status | Body | Cause | Fix |
|---|---|---|---|
| `400` | JSON problem body, `title` `Bad Request` | The body is missing or isn't valid JSON, or a field has the wrong JSON type, such as `"isReusable": "true"` | Send a JSON object. Send `{}` when you have no fields to set |
| `400` | `Payload size exceeds the maximum allowed size of 10000 bytes` | The body is larger than 10,000 bytes | Send fewer or shorter custom fields |
| `400` | `Value is invalid` | The `X-API-Key` value is shorter than 24 characters. On events, `type` or `contact.id` is only spaces. On links, `language` isn't an ISO 639-1 code | Copy the whole key. Fix the field |
| `401` | JSON problem body, `title` `Unauthorized` | The `X-API-Key` header is missing or empty, or the key is wrong, deactivated or deleted | Send an active key. See [Authenticate with an API key](https://docs.pristo.io/cx/api/authentication) |
| `405` | Empty | The request didn't use `POST` | Send `POST` |
| `415` | JSON problem body, `title` `Unsupported Media Type` | The `Content-Type` header isn't `application/json` | Add `Content-Type: application/json` |
| `500` | `Internal server error`, or a JSON problem body | Something failed on the Pristo side | Wait and retry. If it continues, contact Pristo support |

## Send an event

| Status | Body | Cause | Fix |
|---|---|---|---|
| `400` | `contact is required` | The body has no `contact` object | Add `contact` with at least `id` |
| `400` | `type is required and must be between 1 and 50 characters long` | `type` is missing, empty or longer than 50 characters | Send the event type's **Unique Identifier** |
| `400` | `contact.id is required and must be between 1 and 50 characters long` | `contact.id` is missing, empty or longer than 50 characters | Send your ID for the contact |
| `404` | `no population is associated with this api key` | The API key's program has no population | Create the program's population, or use a key from a program that has one |
| `404` | `Population with id not found` | The program's population could not be found when the event was saved | Check the population in the app, then retry |

## Generate a survey link

| Status | Body | Cause | Fix |
|---|---|---|---|
| `400` | `provided surveyId is not valid` | The `prjId` in the path isn't a 22-character questionnaire ID. A full UUID fails too | Copy the ID from the questionnaire's **Share** tab |
| `400` | `expiresInMinutes must be between 1 and 1576800` | `expiresInMinutes` is below 1 or above 1,576,800 | Send 1 to 1,576,800, or leave it out for no expiry |
| `400` | `language must be exactly 2 characters long (iso 639-1)` | `language` isn't 2 characters | Send a code such as `en` or `he` |
| `400` | `title must be at most 50 characters long` | `title` is longer than 50 characters | Shorten the title |
| `400` | `customField values must be strings` | A value in `customFields` is a number, a boolean, an object or an array | Send every value as a string |
| `400` | `customField keys and values must be at most 50 characters long` | A key or a value in `customFields` is longer than 50 characters | Shorten it |
| `404` | `project with id <UUID> not found` | No questionnaire with this ID in the API key's account, or the questionnaire was deleted | Check the ID and the key's account |
| `500` | JSON problem body, `detail` `project does not have a form associated` | The questionnaire has no form | Contact Pristo support with the questionnaire ID |
| `500` | JSON problem body, `detail` `a problem occurred, please try again later` | The questionnaire could not be loaded | Wait and retry |

## Related

- [Pristo API overview](https://docs.pristo.io/cx/api)
- [Send an event](https://docs.pristo.io/cx/api/send-an-event)
- [Generate a survey link](https://docs.pristo.io/cx/api/generate-a-survey-link)
- [API reference](https://docs.pristo.io/cx/api/reference)
