# POST /v1/events

> `POST /v1/events` takes `{ "events": [...] }`, 1 to 500 events per request. Each event needs an `event_name` and a `user_data` that names the person. Every event is judged on its own: the answer is a `200` that counts what was accepted and lists each refused event in `rejected`, with a code to branch on.

Source: https://withbaker.com/docs/events · Updated 2026-11-23

```
POST https://api.withbaker.com/v1/events
```

Sends one or more events about people: a lead, a deal, an order. The field names are Meta's Conversions API's (`event_name`, `event_time`, `event_id`, `user_data`, `value`, `currency`), so an integration you have written against Meta or Google Ads' offline conversions maps over field for field.

**cURL**

```bash
curl -X POST https://api.withbaker.com/v1/events \
  -H "Authorization: Bearer $BAKER_EVENTS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "events": [
    {
      "event_name": "deal_won",
      "event_id": "deal-48213-won",
      "event_time": "2026-11-20T14:03:00Z",
      "user_data": {
        "email": "laura@example.com",
        "external_id": "crm-contact-9921"
      },
      "value": "1200.00",
      "currency": "EUR",
      "properties": {
        "pipeline": "Enterprise",
        "owner": "Marta"
      }
    }
  ]
}'
```

**Node.js**

```js
const response = await fetch("https://api.withbaker.com/v1/events", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.BAKER_EVENTS_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "events": [
      {
        "event_name": "deal_won",
        "event_id": "deal-48213-won",
        "event_time": "2026-11-20T14:03:00Z",
        "user_data": {
          "email": "laura@example.com",
          "external_id": "crm-contact-9921"
        },
        "value": "1200.00",
        "currency": "EUR",
        "properties": {
          "pipeline": "Enterprise",
          "owner": "Marta"
        }
      }
    ]
  }),
});

const { ok, data, error } = await response.json();
if (!ok) throw new Error(`Baker refused the request: ${error.code}`);
// A 200 can still refuse single events: log every one.
for (const refused of data.rejected) console.warn("Baker refused event", refused.index, refused.code, refused.message);
```

**Python**

```python
import os
import requests

response = requests.post(
    "https://api.withbaker.com/v1/events",
    headers={
        "Authorization": f"Bearer {os.environ['BAKER_EVENTS_KEY']}",
    },
    json={
        "events": [
            {
                "event_name": "deal_won",
                "event_id": "deal-48213-won",
                "event_time": "2026-11-20T14:03:00Z",
                "user_data": {
                    "email": "laura@example.com",
                    "external_id": "crm-contact-9921",
                },
                "value": "1200.00",
                "currency": "EUR",
                "properties": {
                    "pipeline": "Enterprise",
                    "owner": "Marta",
                },
            },
        ],
    },
    timeout=10,
)

answer = response.json()
if not answer["ok"]:
    raise RuntimeError(f"Baker refused the request: {answer['error']['code']}")
# A 200 can still refuse single events: log every one.
for refused in answer["data"]["rejected"]:
    print("Baker refused event", refused["index"], refused["code"], refused["message"])
```

**PHP**

```php
<?php
$body = <<<'JSON'
{
  "events": [
    {
      "event_name": "deal_won",
      "event_id": "deal-48213-won",
      "event_time": "2026-11-20T14:03:00Z",
      "user_data": {
        "email": "laura@example.com",
        "external_id": "crm-contact-9921"
      },
      "value": "1200.00",
      "currency": "EUR",
      "properties": {
        "pipeline": "Enterprise",
        "owner": "Marta"
      }
    }
  ]
}
JSON;

$curl = curl_init('https://api.withbaker.com/v1/events');
curl_setopt_array($curl, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('BAKER_EVENTS_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => $body,
]);
$answer = json_decode(curl_exec($curl), true);

if (!$answer['ok']) {
    throw new RuntimeException('Baker refused the request: ' . $answer['error']['code']);
}
// A 200 can still refuse single events: log every one.
foreach ($answer['data']['rejected'] as $refused) {
    error_log("Baker refused event {$refused['index']}: {$refused['code']}");
}
```

**Go**

```go
package main

import (
	"log"
	"net/http"
	"os"
	"strings"
)

const body = `{
  "events": [
    {
      "event_name": "deal_won",
      "event_id": "deal-48213-won",
      "event_time": "2026-11-20T14:03:00Z",
      "user_data": {
        "email": "laura@example.com",
        "external_id": "crm-contact-9921"
      },
      "value": "1200.00",
      "currency": "EUR",
      "properties": {
        "pipeline": "Enterprise",
        "owner": "Marta"
      }
    }
  ]
}`

func main() {
	request, _ := http.NewRequest("POST", "https://api.withbaker.com/v1/events", strings.NewReader(body))
	request.Header.Set("Authorization", "Bearer "+os.Getenv("BAKER_EVENTS_KEY"))
	request.Header.Set("Content-Type", "application/json")

	response, err := http.DefaultClient.Do(request)
	if err != nil {
		log.Fatal(err) // it may have arrived: retry with the same event_ids, which then count once
	}
	defer response.Body.Close()
	// Decode the answer and log every entry of data.rejected: a 200 can still refuse single events.
	log.Println("Baker answered", response.Status)
}
```

## Try it

Press **Test Request** on withbaker.com/docs to send any example to the real API. With the public test key, `bk_test_public`, it is checked exactly like yours and nothing is stored. Sign in at the top of the page to send with your company's key instead.

**Try it.** Send this to the real API with the public test key, `bk_test_public`: it is checked exactly like a company's request, answered the same way with `"mode": "test"`, and nothing is stored.

```bash
curl -X POST https://api.withbaker.com/v1/events \
  -H "Authorization: Bearer bk_test_public" \
  -H "Content-Type: application/json" \
  -d '{"events":[{"event_name":"deal_won","event_id":"deal-48213-won","event_time":"2026-11-20T14:03:00Z","user_data":{"email":"laura@example.com","external_id":"crm-contact-9921"},"value":"1200.00","currency":"EUR","properties":{"pipeline":"Enterprise","owner":"Marta"}}]}'
```

## Headers

| Field | | What it takes |
| --- | --- | --- |
| `Authorization` | required | Bearer \<your sending key> |
| `Content-Type` | required | application/json |
| `X-Baker-Mode` | optional | live (the default) or test.<br>A test send is authenticated and validated identically and stores nothing. An unrecognised value is refused rather than assumed. |

## Body

A JSON object with one field, `events`: an array of 1 to 500 events, 8 MB at most. Any other top-level field is refused with a `400`, and so is any field an event does not define: a field you misspell is reported rather than silently dropped.

| Field | | What it takes |
| --- | --- | --- |
| `event_name` | required | What happened. Up to 80 characters of letters, digits, spaces, . _ and -, starting with a letter or a digit<br>The only required field. Use one of the standard names below wherever one fits; anything else is yours to invent, in whatever language you name things in: a letter is a letter in any script, and "Matrícula Realizada" is a name. |
| `event_time` | optional | ISO-8601 with an offset (2026-09-08T13:23:41Z), or Unix seconds (1757337821).<br>Left out, it is the moment we received it. Nothing is refused for being old: a backfill of last year's history is what this is for. More than 5 minutes in the future is refused. |
| `event_id` | optional | Your own id for this event: 1–128 characters of letters, digits, and . _ : -<br>Send one only if you want it deduplicated: the same id twice is counted once. Send none and every post is its own event. |
| `user_data` | required | Who it was about. At least one field below: this is the whole of how a server event finds the person who visited a Baker page or your website.<br>No field is required on its own and the block is: an event naming nobody is refused with missing_identity. The one exception is a page_view carrying a url, because a page serve is a fact about a page. |
| ↳ `email` | optional | The address, or its SHA-256 digest if you already hash. Either works: we tell them apart.<br>Send this one if you can. It is the road that cannot silently fail: we normalise and hash it here, so it lands on exactly the person a Baker page or the pixel already recorded. |
| ↳ `phone` | optional | The number with its country code, or its digest. Same treatment as email. |
| ↳ `external_id` | optional | Your own id for the person, such as a CRM contact key.<br>Kept exactly as you send it, and hashed alongside so it joins: your own events to each other, and to a browser once one event carries it beside an email or a baker_id. |
| ↳ `baker_id` | optional | The Baker ID one of our pages already gave this browser, if you kept it.<br>The strongest of all of them: it names the visit, so the event lands on that person's timeline rather than beside it. |
| ↳ `the ad click ids` | optional | The click id that brought them, if you kept it, under the name the platform stamps on the link: gclid, wbraid, gbraid, dclid, fbclid, ttclid, twclid, li_fat_id, msclkid, rdt_cid, epik, sccid (Snapchat's ScCid, in any case), oppref (ChatGPT Ads).<br>A click id names a person too: it is enough on its own, and it attributes the event to the campaign that earned it. |
| ↳ `fbp, fbc` | optional | Meta's own browser cookies (_fbp, _fbc), exactly as your site stored them.<br>Enough on their own, and worth sending: they are what Meta matches a server event on. We read the click id out of an fbc for you. |
| ↳ `the matching fields` | optional | first_name, last_name, date_of_birth, gender, street, city, region, postal_code, country: Meta's advanced matching and Google's enhanced conversions, in one block. Plain or already hashed.<br>They name nobody here, so they never satisfy user_data on their own. They are kept so this event can be sent on to Meta or Google later without asking you for it all again. |
| `url` | optional | The full page URL this happened on.<br>Its query string is where campaign parameters and ad click ids are read from. Without it the event counts, and belongs to no page. |
| `value` | optional | What it was worth: a decimal string or a JSON number. No thousands separator, no sign, no exponent.<br>Rounded to what the currency holds: 1200.999 EUR is stored as 1201.00. "1,200" is refused. |
| `currency` | conditional | An ISO-4217 code, e.g. EUR. Required whenever value is present, and refused on its own. |
| `properties` | optional | A flat object of strings: anything you want to break the event down by later. |
| `items` | optional | What was bought, one entry per product line, for a purchase, a cart or a refund.<br>Each line names its product by at least one of the ids below. value still carries the whole event's money. An order with more than 250 lines keeps the first 250. |
| ↳ `product_id, variant_id, feed_id` | conditional | Your store's product id, its variant id, or the id the product has in your ads catalog. At least one per line, up to 255 characters each. |
| ↳ `quantity` | optional | How many: a whole number from 1 to 1,000,000. |
| ↳ `price` | optional | The price of one unit, in the event's currency, so it needs currency. A decimal like value. |
| `consent` | optional | What the person allowed, if your site asked them.<br>Send it whenever you know it. A person who said no to marketing is still counted in your reports, and is never matched or sent to an ad platform. |
| ↳ `analytics` | optional | granted or denied: whether they allowed being measured. Denied keeps the event and forgets who it was. |
| ↳ `marketing` | optional | granted or denied: whether they allowed their visit to be used for advertising. |

Limits inside an event: `event_name` up to 80 characters; `event_id` 1 to 128 characters; up to 250 `items`, each id up to 255 characters and `quantity` up to 1,000,000.

> **Heads-up:** **What refuses the whole request.** The shape is checked for the batch as a whole: an unknown field, a field of the wrong JSON type (a number in `properties`, an object in `value`) or an event with no `event_name` at all refuses every event with a `400`, and the message names the path, such as `events.3.event_name`. Everything else about an event, a missing person, a bad amount, a future time, refuses that event alone, inside a `200`. Validate the shape before you send with the [JSON Schema](https://withbaker.com/docs/event-batch.schema.json).

> **Tip:** **Send money as a string.** In JavaScript, `JSON.stringify` writes a very small or very large number with an exponent (`1e-7`), which is refused. `amount.toFixed(2)` (or the currency's own decimals) always works. Currency codes are uppercase: `EUR`, not `eur`.

**required** means the event is refused without it: with no `event_name` the request is a `400`; with a `user_data` that names nobody, that event is `missing_identity`. `X-Baker-Mode` is read without regard to case or spaces.

## Response

Every request that could be read answers `200` with this shape, whatever happened to each event:

```json
{
  "ok": true,
  "data": {
    "mode": "live",
    "received": 2,
    "accepted": 1,
    "rejected": [
      {
        "index": 1,
        "event_id": "",
        "code": "invalid_value",
        "message": "value and currency go together: a non-negative decimal and an ISO-4217 code"
      }
    ]
  }
}
```

| Field | | What it takes |
| --- | --- | --- |
| `mode` | required | live or test, echoed back, so a forgotten header is visible in the reply rather than in a report next week. |
| `received` | required | How many events we read, so you can detect a truncated body. |
| `accepted` | required | How many were counted. |
| `rejected` | required | One entry per refused event: index, event_id, code, message.<br>index is the position in your own array, and is the one to branch on: event_id is empty for an event that sent none. |

The counts never say which person matched or whether an address is already known to Baker. That is deliberate: a leaked key must not be able to ask who is in your data.

## Rejection codes

`rejected[].code` is a closed set. Branch on it, never on `message`, which is written for people and may change.

| Code | Means | Fix |
| --- | --- | --- |
| `invalid_event_id` | event_id, when sent, must be 1-128 characters of A-Z a-z 0-9 . _ : - | Send an id of 1 to 128 letters, digits and `. _ : -`, or leave `event_id` out. |
| `invalid_name` | event_name is required: up to 80 characters of letters (any language), digits, spaces, . _ and -, starting with a letter or a digit | Send a name of up to 80 characters that starts with a letter or a digit. |
| `missing_identity` | user_data named nobody, and no url named a page | Add at least one way to name the person in `user_data`: an email, a phone, your own `external_id`, a `baker_id`, a click id, `fbp` or `fbc`. A value that is not one (an email with no `@`) names nobody. |
| `invalid_timestamp` | event_time must be an ISO-8601 instant with an offset or Unix seconds, and not in the future | Send ISO-8601 with an offset (`2026-11-20T14:03:00Z`) or Unix seconds (not milliseconds: `Math.floor(Date.now() / 1000)`), no more than 5 minutes ahead. |
| `invalid_value` | value and currency go together: a non-negative decimal and an ISO-4217 code | Send `value` as a plain non-negative decimal (`1200.50`, no thousands separator, no exponent) with an uppercase ISO-4217 `currency` (`EUR`, not `eur`). |
| `batch_too_large` | a request carries at most 500 events and 8 MB | Never in `rejected`: it is the `413` for the whole request. Split it: at most 500 events and 8 MB each. |
| `invalid_items` | each item names a product_id, variant_id or feed_id; quantity is a whole number from 1 to 1000000; price is a non-negative decimal sent with a currency | Name each line by `product_id`, `variant_id` or `feed_id`; send `quantity` from 1 to 1,000,000 and `price` with a `currency`. |
| `invalid_consent` | consent.analytics and consent.marketing, when sent, are granted or denied | Send `granted` or `denied`, or leave the field out. |

## HTTP statuses

| Status | Code | Means | Retry |
| --- | --- | --- | --- |
| `200` | `ok: true` | The request was read. Single events may still be refused: read `data.rejected`. | No |
| `400` | `invalid_request` | The body is not the documented shape, anywhere in the batch: not JSON, an unknown field, a field of the wrong JSON type, an event with no event_name, or an X-Baker-Mode that is neither live nor test. Fix the request. The message names the first field that is wrong by its path, such as events.3.event_name. | No |
| `401` | `invalid_api_key` | The key is missing, mistyped or revoked. Check the Authorization header and the key in Baker. | No |
| `403` | `forbidden` | The key is valid but may not send events, the company's Baker account is closed, or the public test key was asked to go live. Use a key created as Sending events only. The public test key only rehearses. | No |
| `413` | `batch_too_large` | More events, or more bytes, than one request may carry. Split the batch and send each half. | After splitting |
| `429` | `rate_limited` | Over the requests-per-minute budget: the company's, or the public test key's. Wait for the seconds in Retry-After, then send the same request again. | Yes |
| `500` | `internal_error` | A fault on our side. Nothing was written. Retry with exponential backoff, with the same event_ids. | Yes |

How to retry, and why it is always safe with an `event_id`: [Errors and retries](https://withbaker.com/docs/errors.md).

## Need help?

Write to support@withbaker.com: a person answers within 24 hours. The OpenAPI description is at https://withbaker.com/docs/openapi.json.
