# Responses and errors

> What the Events API returns, every status code and its cause, and how batches, validation and timeouts behave.

## Always HTTP 200

`POST /add/events/v1.json` answers **HTTP 200 for every request it can read**, accepted or rejected. The result is in the `statusCode` field of the body. Do not rely on the HTTP status to know whether an event was stored.

A rejected request returns only two fields:

```json
{ "statusCode": "NO_SESSIONID", "timestamp": 1757491200000 }
```

## A successful response

```json
{
  "statusCode": "SUCCESS",
  "timestamp": 1757491200000,
  "responses": [[]],
  "campaigns": [[]],
  "search": [[]],
  "suggests": [[]],
  "coupons": [],
  "experiments": {}
}
```

| Field | Type | Description |
| --- | --- | --- |
| `statusCode` | string | `SUCCESS`. |
| `timestamp` | integer | Server time in Unix milliseconds. |
| `responses` | array of arrays | One entry per event you sent, in the same order. Holds the output of the recommendation campaigns that ran for that event, with the products to show. |
| `campaigns` | array of arrays | One entry per event. Holds engagement campaigns to show: popups, banners, push permission prompts. |
| `search` | array of arrays | One entry per event. Holds results for `SEARCH` events. |
| `suggests` | array of arrays | One entry per event. Holds search suggestions. |
| `coupons` | array | Coupons assigned to the user. |
| `experiments` | object | A/B tests the user takes part in. |
| `u` | object | State of the user. |

An entry is an empty array when no campaign answered that event. The content of an entry depends on the campaigns set up in your panel.

## Status codes

Checks run in the order of this table. The first one that fails decides the status.

| `statusCode` | Cause | Fix |
| --- | --- | --- |
| `NO_API_KEY` | The `apiKey` query parameter is missing or empty. | Add `?apiKey=` to the URL. |
| `NO_ACCOUNT` | No account has this API key on this data center. | Check the key and the data center host. |
| `FAILED_ACCOUNT` | The account is inactive. | Contact the Segmentify support team. |
| `ONHOLD_ACCOUNT` | The account is on hold. | Contact the Segmentify support team. |
| `NO_DOMAIN_APIKEY_MATCH` | The `Origin` header (or `Referer`, when there is no `Origin`) does not contain a domain of the account. | Send your registered domain in `Origin`. |
| `NO_EVENT` | The body could not be read as events: it is empty, not valid JSON, or a field holds a value that is not allowed (for example an unknown `step`, or text where a number is expected). | Validate the JSON, then compare values with [Event fields and types](/events/event-fields/). |
| `NO_USERID` | An event has no `userId`, or it is the text `"undefined"`. | Send a `userId` with every event. |
| `NO_SESSIONID` | An event has no `sessionId`, or it is the text `"undefined"`. | Send a `sessionId` with every event. |
| `BOT` | The `userAgent` of an event is recognised as a bot. | Send the visitor's real user agent. |
| `UNDEFINED_LANGUAGE` | `lang` is not a language of the account. A missing `lang` counts as `EN`. | Send a configured language. |
| `UNDEFINED_CURRENCY` | `currency` is not a currency of the account. | Send a configured currency. |
| `UNDEFINED_REGION` | `region` is not a region of the account. | Send a configured region, or leave it out. |
| `INVALID_EVENT` | The event breaks a rule of its type: a value above its limit, or a missing field that the event needs. | See the rules below. |
| `EXCLUDED_EVENT` | The event matches an exclusion set for the account, for example an excluded IP address. | Check the exclusions of the account. |
| `TIMEOUT` | Processing took longer than 10 seconds. | Retry later. |
| `ERROR` | An unexpected error. | Retry later; if it persists, contact support with the request. |

### What makes an event invalid

| Event | Rule |
| --- | --- |
| `PRODUCT_VIEW` | `price`, `oldPrice`, `specialPrice` at most 9,000,000,000. `stockCount` not negative. `stockRatio`, `stockStatus` between 0 and 100. `url` and `image` on the allowed domains, if the account restricts them. |
| `BASKET_OPERATIONS` | `quantity` at most 1,000,000. `price` at most 9,000,000,000. |
| `CHECKOUT` | `totalPrice` at most 90,000,000,000. Each product: `quantity` at most 1,000,000, `price` at most 9,000,000,000. |
| `INTERACTION` | `instanceId` present. `type` one of the accepted values. |
| `WISHLIST` | `productId` present for `add`, `remove`, `detail`. `favoritesList` present for `view-favorites`. |

## Batches

- One request can carry many events in a JSON array. They are processed in order.
- **A batch is accepted or rejected as a whole.** If one event fails a check, none of the events is stored, and the status names the first failure.
- In a successful response, entry `i` of `responses`, `campaigns` and `search` belongs to event `i` of your array.

## Things that do not cause an error

These pass with `SUCCESS` and are easy to miss:

- **An unknown field name.** It is ignored. `prodcutId` instead of `productId` loses the value without a warning.
- **`oldPrice` not greater than `price`.** The old price is dropped.
- **A test event.** `testMode: true` succeeds but is kept apart from live data.

## Request format

- Method `POST`, body JSON. `Content-Type` may be `application/json` or `text/plain`.
- The body is an array of events. A single event object is accepted as an array of one.
- Field names are case-sensitive.
