API reference
Every v1 endpoint with its fields, responses, and examples in curl, Node.js, Python, PHP, Ruby, and Go.
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
| Field | Type | Description |
|---|---|---|
typeRequired | string | Your event name: lowercase letters, digits, _, : and -. Graytower's built-in event names are reserved. |
eventIdRequired | string | A 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. |
anonymousIdRequired | string (UUID) | The visitor's ID from the browser tracker, so the event joins their journey. On cookieless websites it's ignored. |
occurredAtOptional | string (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. |
paramsOptional | object | Up 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. |
{ "type": "account_created", "eventId": "0193a3f0-7c4e-7a51-8b2d-4f6e9c1d2a3b", "anonymousId": "123e4567-e89b-42d3-a456-426614174000", "params": { "plan": "pro" }}| Status | Meaning |
|---|---|
| 202 | Accepted, or already accepted earlier (duplicate). |
| 400 | invalid_payload (permanent), stale_event (permanent) |
| 401 | unauthorized (permanent) |
| 403 | forbidden (permanent) |
| 413 | payload_too_large (permanent) |
| 429 | rate_limited (retry), quota_exceeded (retry after) |
| 500 | internal_error (retry) |
| 503 | unavailable (retry) |
{ "data": { "eventId": "0193a3f0-7c4e-7a51-8b2d-4f6e9c1d2a3b", "status": "accepted" }}curl https://graytower.app/api/v1/events \ -H "Authorization: Bearer $GRAYTOWER_SERVER_EVENT_KEY" \ -H "Content-Type: application/json" \ -d '{"type":"account_created","eventId":"0193a3f0-7c4e-7a51-8b2d-4f6e9c1d2a3b","anonymousId":"123e4567-e89b-42d3-a456-426614174000"}'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 }),});import osimport uuid # uuid.uuid7() needs Python 3.14+; earlier versions: pip install uuid6
import requests
response = requests.post( "https://graytower.app/api/v1/events", headers={"Authorization": f"Bearer {os.environ['GRAYTOWER_SERVER_EVENT_KEY']}"}, json={"type": "account_created", "eventId": str(uuid.uuid7()), "anonymousId": visitor_id}, timeout=10,)<?php// composer require ramsey/uuiduse Ramsey\Uuid\Uuid;
$ch = curl_init('https://graytower.app/api/v1/events');curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('GRAYTOWER_SERVER_EVENT_KEY'), 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => json_encode([ 'type' => 'account_created', 'eventId' => Uuid::uuid7()->toString(), 'anonymousId' => $visitorId, ]),]);$body = json_decode(curl_exec($ch), true);$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);require "json"require "net/http"require "securerandom" # SecureRandom.uuid_v7 needs Ruby 3.3+
uri = URI("https://graytower.app/api/v1/events")request = Net::HTTP::Post.new(uri)request["Authorization"] = "Bearer #{ENV.fetch('GRAYTOWER_SERVER_EVENT_KEY')}"request["Content-Type"] = "application/json"request.body = { type: "account_created", eventId: SecureRandom.uuid_v7, anonymousId: visitor_id }.to_json
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 10) do |http| http.request(request)end// go get github.com/google/uuideventID, err := uuid.NewV7()if err != nil { return err}body, _ := json.Marshal(map[string]any{ "type": "account_created", "eventId": eventID.String(), "anonymousId": visitorID,})req, _ := http.NewRequest("POST", "https://graytower.app/api/v1/events", bytes.NewReader(body))req.Header.Set("Authorization", "Bearer "+os.Getenv("GRAYTOWER_SERVER_EVENT_KEY"))req.Header.Set("Content-Type", "application/json")resp, err := (&http.Client{Timeout: 10 * time.Second}).Do(req)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.
| Field | Type | Description |
|---|---|---|
operationsRequired | array of EventOperation | at least 1, at most 100 |
{ "operations": [ { "type": "account_created", "eventId": "0193a3f0-7c4e-7a51-8b2d-4f6e9c1d2a3b", "anonymousId": "123e4567-e89b-42d3-a456-426614174000", "params": { "plan": "pro" } } ]}| Status | Meaning |
|---|---|
| 202 | One result per operation, in request order. |
| 400 | invalid_payload (permanent) |
| 401 | unauthorized (permanent) |
| 403 | forbidden (permanent) |
| 413 | payload_too_large (permanent) |
| 429 | rate_limited (retry), quota_exceeded (retry after) |
| 500 | internal_error (retry) |
| 503 | unavailable (retry) |
{ "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).
| Field | Type | Description |
|---|---|---|
checkoutSessionIdOptional | string | A Checkout Session on the connected Stripe account.at least 1 characters, at most 255 characters |
paymentIntentIdOptional | string | A PaymentIntent on the connected Stripe account.at least 1 characters, at most 255 characters |
visitorIdOptional | string | The visitor's ID from the browser tracker. Not available on cookieless websites. |
userIdOptional | string | Your 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.
{ "paymentIntentId": "pi_3QxYzAbCdEfGhIjK", "visitorId": "123e4567-e89b-42d3-a456-426614174000", "userId": "user_42"}| Status | Meaning |
|---|---|
| 200 | The attribution is recorded. |
| 400 | invalid_payload (permanent) |
| 401 | unauthorized (permanent) |
| 403 | forbidden (permanent) |
| 409 | identity_mode_limited (permanent), stripe_not_connected (permanent), checkout_incomplete (permanent), payment_intent_unavailable (permanent), metadata_conflict (permanent) |
| 413 | payload_too_large (permanent) |
| 429 | rate_limited (retry) |
| 500 | internal_error (retry) |
| 503 | unavailable (retry) |
{ "data": { "paymentIntentId": "pi_3QxYzAbCdEfGhIjK", "updated": true, "ingested": false }}curl https://graytower.app/api/v1/payments/attribution \ -H "Authorization: Bearer $GRAYTOWER_STRIPE_ATTRIBUTION_KEY" \ -H "Content-Type: application/json" \ -d '{"paymentIntentId":"pi_3QxYzAbCdEfGhIjK","visitorId":"123e4567-e89b-42d3-a456-426614174000"}'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 }),});requests.post( "https://graytower.app/api/v1/payments/attribution", headers={"Authorization": f"Bearer {os.environ['GRAYTOWER_STRIPE_ATTRIBUTION_KEY']}"}, json={"paymentIntentId": intent.id, "visitorId": visitor_id, "userId": str(user.id)}, timeout=10,)<?php$ch = curl_init('https://graytower.app/api/v1/payments/attribution');curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('GRAYTOWER_STRIPE_ATTRIBUTION_KEY'), 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => json_encode([ 'paymentIntentId' => $intent->id, 'visitorId' => $visitorId, 'userId' => (string) $user->id, ]),]);$body = json_decode(curl_exec($ch), true);uri = URI("https://graytower.app/api/v1/payments/attribution")request = Net::HTTP::Post.new(uri)request["Authorization"] = "Bearer #{ENV.fetch('GRAYTOWER_STRIPE_ATTRIBUTION_KEY')}"request["Content-Type"] = "application/json"request.body = { paymentIntentId: intent.id, visitorId: visitor_id, userId: user.id.to_s }.to_json
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 10) do |http| http.request(request)endbody, _ := json.Marshal(map[string]any{ "paymentIntentId": intent.ID, "visitorId": visitorID, "userId": userID,})req, _ := http.NewRequest("POST", "https://graytower.app/api/v1/payments/attribution", bytes.NewReader(body))req.Header.Set("Authorization", "Bearer "+os.Getenv("GRAYTOWER_STRIPE_ATTRIBUTION_KEY"))req.Header.Set("Content-Type", "application/json")resp, err := (&http.Client{Timeout: 10 * time.Second}).Do(req)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.
| Prefix | Key | Status |
|---|---|---|
gts_ | Server key: custom events and payment attribution | Issued |
gtt_ | Test-mode events | Reserved |
gtp_ | First-party proxy | Reserved |
gtc_ | Crawler hits | Reserved |
gtr_ | Reading analytics | Reserved |
gta_ | Account management | Reserved |
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.