Search documentation

Search titles, headings, and page summaries.

API reference

Every v1 endpoint with its fields, responses, and examples in curl, Node.js, Python, PHP, Ruby, and Go.

Updated 2026-12-05

This reference is generated from the OpenAPI 3.1 document at https://graytower.app/api/v1/openapi.json, so it always matches what the API accepts. Load that file into an API client or a code generator if you prefer.

Every request needs a server key from Website → Settings → Developer (see Server authentication) and Content-Type: application/json. Errors share one format, described in Errors and retries.

Send one event

POST https://graytower.app/api/v1/events

FieldTypeDescription
typeRequiredstringYour event name: lowercase letters, digits, _, : and -. Graytower's built-in event names are reserved.
eventIdRequiredstringA UUIDv7 you generate once per event and reuse on every retry. Its time must be within the last 24 hours (and at most 5 minutes ahead). Graytower counts each eventId once per website.
anonymousIdRequiredstring (UUID)The visitor's ID from the browser tracker, so the event joins their journey. On cookieless websites it's ignored.
occurredAtOptionalstring (date-time)When the event happened. If omitted, Graytower uses the time inside the UUIDv7 eventId, so every retry stores the same event. ISO 8601 with a timezone, within the last 24 hours and at most 5 minutes ahead.
paramsOptionalobjectUp to 10 string values. Numbers and booleans aren't converted: send them as strings.at most 10 keys
kindOptional"event"Optional. "event" is the only kind today; identify arrives in a later version.
Example request
{  "type": "account_created",  "eventId": "0193a3f0-7c4e-7a51-8b2d-4f6e9c1d2a3b",  "anonymousId": "123e4567-e89b-42d3-a456-426614174000",  "params": {    "plan": "pro"  }}
StatusMeaning
202Accepted, or already accepted earlier (duplicate).
400invalid_payload (permanent), stale_event (permanent)
401unauthorized (permanent)
403forbidden (permanent)
413payload_too_large (permanent)
429rate_limited (retry), quota_exceeded (retry after)
500internal_error (retry)
503unavailable (retry)
Example 202 response
{  "data": {    "eventId": "0193a3f0-7c4e-7a51-8b2d-4f6e9c1d2a3b",    "status": "accepted"  }}
JavaScript
import { v7 as uuidv7 } from "uuid"; // npm install uuid
const response = await fetch("https://graytower.app/api/v1/events", {  method: "POST",  headers: {    Authorization: `Bearer ${process.env.GRAYTOWER_SERVER_EVENT_KEY}`,    "Content-Type": "application/json",  },  body: JSON.stringify({ type: "account_created", eventId: uuidv7(), anonymousId: visitorId }),});

Store the eventId with the action if you retry later: a retry must send the same ID.

Send a batch of events

POST https://graytower.app/api/v1/events/batch

At most 100 operations and 256 KB per request; each operation at most 16 KB. Operations are processed in order. A problem with one event rejects only that event; rate, quota and server errors fail the whole request with no results, so retry every event in it.

FieldTypeDescription
operationsRequiredarray of EventOperationat least 1, at most 100
Example request
{  "operations": [    {      "type": "account_created",      "eventId": "0193a3f0-7c4e-7a51-8b2d-4f6e9c1d2a3b",      "anonymousId": "123e4567-e89b-42d3-a456-426614174000",      "params": {        "plan": "pro"      }    }  ]}
StatusMeaning
202One result per operation, in request order.
400invalid_payload (permanent)
401unauthorized (permanent)
403forbidden (permanent)
413payload_too_large (permanent)
429rate_limited (retry), quota_exceeded (retry after)
500internal_error (retry)
503unavailable (retry)
Example 202 response
{  "data": {    "results": [      {        "eventId": "0193a3f0-7c4e-7a51-8b2d-4f6e9c1d2a3b",        "status": "accepted"      },      {        "eventId": "0193a3f0-7c4f-7b02-9c3e-5a7f0d2e3b4c",        "status": "duplicate"      },      {        "eventId": "0193a3f0-7c50-7c13-8d4f-6b8a1e3f4c5d",        "status": "rejected",        "error": {          "code": "invalid_payload",          "details": [            {              "path": "operations.2.type",              "issue": "invalid_value"            }          ]        }      }    ]  }}

The request wraps the same event objects in operations. Every language example above works with the batch URL and a body of { "operations": [ … ] }.

Attribute a payment

POST https://graytower.app/api/v1/payments/attribution

Stripe stays the source of truth for the amount: this only records who paid. Call it once a PaymentIntent exists: right after creating a PaymentIntent, or after a Checkout Session completes (a new Checkout Session may not have one yet).

FieldTypeDescription
checkoutSessionIdOptionalstringA Checkout Session on the connected Stripe account.at least 1 characters, at most 255 characters
paymentIntentIdOptionalstringA PaymentIntent on the connected Stripe account.at least 1 characters, at most 255 characters
visitorIdOptionalstringThe visitor's ID from the browser tracker. Not available on cookieless websites.
userIdOptionalstringYour own user ID. Leading and trailing spaces are trimmed.at least 1 characters, at most 256 characters

Exactly one of checkoutSessionId or paymentIntentId, and at least one of visitorId or userId.

Example request
{  "paymentIntentId": "pi_3QxYzAbCdEfGhIjK",  "visitorId": "123e4567-e89b-42d3-a456-426614174000",  "userId": "user_42"}
StatusMeaning
200The attribution is recorded.
400invalid_payload (permanent)
401unauthorized (permanent)
403forbidden (permanent)
409identity_mode_limited (permanent), stripe_not_connected (permanent), checkout_incomplete (permanent), payment_intent_unavailable (permanent), metadata_conflict (permanent)
413payload_too_large (permanent)
429rate_limited (retry)
500internal_error (retry)
503unavailable (retry)
Example 200 response
{  "data": {    "paymentIntentId": "pi_3QxYzAbCdEfGhIjK",    "updated": true,    "ingested": false  }}
JavaScript
await fetch("https://graytower.app/api/v1/payments/attribution", {  method: "POST",  headers: {    Authorization: `Bearer ${process.env.GRAYTOWER_STRIPE_ATTRIBUTION_KEY}`,    "Content-Type": "application/json",  },  body: JSON.stringify({ paymentIntentId: intent.id, visitorId, userId: user.id }),});

Versioning

Version 1 only changes in ways that keep working integrations working: new endpoints, new optional fields, and new error codes. Handle an unknown error code like the closest status code you know.

A field or endpoint is removed only with at least six months' notice. The changelog announces it, and affected responses carry a Deprecation header and a Sunset header with the date it stops working.

Key prefixes

Each kind of key has its own prefix, so a key that ends up in the wrong place is easy to recognise. Only server keys are issued today; the others are reserved.

PrefixKeyStatus
gts_Server key: custom events and payment attributionIssued
gtt_Test-mode eventsReserved
gtp_First-party proxyReserved
gtc_Crawler hitsReserved
gtr_Reading analyticsReserved
gta_Account managementReserved

Sending a reserved kind of key to these endpoints returns 403 forbidden, with a message naming the key it needs. The browser write key from your tracking snippet has no prefix and never works on these endpoints.