Errors and retries
Every error from the JustAI data APIs tells you whether to fix the request or to retry it. A 5xx error, a 429, or a timeout is temporary. Retry those with backoff, and keep the same body, messageId, and timestamp so that a retry has no extra effect. Any other 4xx error means that the request, the key, or the URL needs a change. An unchanged request fails the same way again.
Status codes
Section titled “Status codes”| Status | API | Body | Cause | Action |
|---|---|---|---|---|
400 |
All | {"error":"Invalid org slug"} |
The path value is not a valid slug. For example, it has an uppercase letter. | Fix the slug in the path. |
400 |
All | {"error":"Invalid environment"} |
The X-JustAI-Environment header is empty or badly formatted, for example Prod. |
Send the exact environment key, or leave the header out for Production. |
400 |
Identify | {"error":"Invalid Identify call","issues":[...]} |
The body failed validation. | Fix each listed issue. See Identify errors. |
400 |
Identify | {"error":"timestamp cannot be more than 5 minutes in the future"} |
timestamp is more than 5 minutes ahead of JustAI’s clock. |
Check your clock and the time zone of the timestamp. |
400 |
Track | {"error":"<message>"} |
The body failed validation. The message describes the first problem. | Fix the body. See Track errors. |
401 |
All | {"error":"Missing API key"} |
The request has no key in X-Api-Key or Authorization. |
Add the key. |
401 |
All | {"error":"Invalid API key"} |
The key is unknown or revoked. | Check the key’s status in Settings > API keys, or create a new key. |
403 |
All | {"error":"Forbidden"} |
The key, organization, path value, and environment do not match, or the environment was removed. | Use a key created in the same environment as the path value and header. |
404 |
All | 404 Not Found (plain text) |
The path is unknown, the method is wrong, or the path ends with a slash. | Fix the URL and the method. |
404 |
Profiles | {"error":"Profile not found"} |
No profile in this environment has this user ID. | Check the user ID and the environment. After the first Identify call for a user, wait a minute and read again. |
413 |
Identify | {"error":"Identify call is too large"} |
The call is over the size limit of about 1 MB. | Send fewer or smaller traits. |
413 |
Track | {"error":"Track event is too large"} |
The event is over the size limit of about 1 MB. | Make the event smaller. |
429 |
All | Not always JSON | A network layer between your system and JustAI asked you to slow down. | Retry with backoff, and lower your concurrency. |
500 |
All | {"error":"Internal error"} |
An unexpected server error. | Retry with backoff. |
503 |
Identify | {"error":"Profile storage is unavailable"} |
JustAI could not accept the call at that moment. | Retry with backoff, with the same body, messageId, and timestamp. |
503 |
Track | {"error":"Event storage is unavailable"} |
JustAI could not accept the event at that moment. | Retry with backoff, with the same body and messageId. |
Order of checks
Section titled “Order of checks”JustAI checks each request in this order and returns the first failure:
- The path and method match an endpoint (
404). - The slug in the path has a valid format (
400). - The
X-JustAI-Environmentheader, if present, has a valid format (400). - A key is present (
401). - The key is valid (
401). - The key, organization, path value, and environment match (
403). - The request body is valid (
400or413).
A bad slug or a bad environment header returns 400 even when the request has no key.
Error body shapes
Section titled “Error body shapes”| Shape | Returned by | Example |
|---|---|---|
| Error string | Every JSON error | {"error":"Forbidden"} |
| Error string with issues | Identify validation errors | {"error":"Invalid Identify call","issues":[{"code":"custom","message":"At least one trait is required unless consent is provided","path":["traits"]}]} |
| Plain text | An unknown path or method | 404 Not Found |
The two write APIs report validation errors differently:
- Identify lists every issue. Each issue has a
code, apathto the field, and amessage. - Track returns only the first problem’s message, and the message does not name the field. For example, a missing
timestampreturns{"error":"Required"}.
Retry temporary failures
Section titled “Retry temporary failures”Retry these responses:
500and503429- a timeout, or a connection that closes before you get a response
Do not retry 400, 401, 403, 404, or 413 until you change the request, the key, or the URL. They fail the same way every time, with two exceptions:
- A Profiles
404right after the first Identify call for a user. Wait a minute and read again. - A
401with{"error":"Invalid API key"}just after you create a key. Wait briefly and try again; confirm it works before switching traffic.
Use bounded exponential backoff with jitter. The values below are a starting point. Tune them for your system.
- Wait a short time, such as 1 second, before the first retry.
- Double the wait after each failed attempt, up to a maximum wait, such as 1 minute.
- Add a random amount to each wait, so that your clients do not all retry at the same moment.
- Stop after a fixed number of attempts. Keep the failed request so that you can replay it later.
On every retry, resend the identical request with the same body and the same messageId. For Identify, this includes the same timestamp.
If many requests fail with 5xx at the same time, lower your concurrency before you retry.
When you do not know whether a request succeeded
Section titled “When you do not know whether a request succeeded”A timeout does not mean that the request failed. JustAI can accept a request before the connection drops. Retry the identical request:
- Identify returns
202again. A retry with the sametimestampchanges nothing that the first call already applied. - Track returns
202again and counts the event once.
Duplicates and idempotency
Section titled “Duplicates and idempotency”Each write API makes retries safe in its own way:
| Behavior | Identify | Track |
|---|---|---|
messageId |
Optional. JustAI generates one if you leave it out. | Required. |
| What makes a retry safe | The timestamp. Each trait keeps its own update time, so a retry with the same timestamp changes nothing and starts no journey. |
The messageId. JustAI counts the event once and starts a journey at most once. |
| Identical retry | 202. It changes nothing that the first call already applied. |
202. |
Same messageId, different content |
202. JustAI applies the call, unless it already recorded a journey change under this messageId. Then it applies nothing, and the response doesn’t say so. Do not do this. Send a correction with a new messageId. |
202. Do not do this. Send a correction as a new event with a new messageId. |
Follow these rules for both APIs:
- Use a new
messageIdfor every new update or event. - Reuse a
messageIdonly to retry the same request. - Always send
timestampon Identify. Without it, JustAI uses the time it receives the call, and a retry that arrives after a newer update to the same trait overwrites that update. - Send an Identify correction or a new consent decision with a new
messageId. If JustAI already recorded a journey change under the old one, it applies nothing from the call, and the response doesn’t say so. - Never reuse a Track
messageIdto correct an event. JustAI can’t edit or delete an accepted event. If you send a corrected event with a newmessageId, JustAI records it in addition to the original, and it can start a matching journey again. To remove events, contact your JustAI team.
When to leave out the Identify messageId
Section titled “When to leave out the Identify messageId”Leave messageId out when your sync tool can’t give every new update a new ID. JustAI generates one for each call. Send timestamp either way.
To send your own ID from a warehouse or reverse ETL sync, build it from values that change whenever any synced value changes, such as a hash of the user ID, the update time, and every synced trait. The Hightouch profile sync template builds it this way.
Log errors without exposing secrets
Section titled “Log errors without exposing secrets”Log enough to find and replay a failed request:
- the endpoint path and method
- the status code and the response body
- the
messageIdand the user ID - the attempt number and the time
Never log an API key. Remove the X-Api-Key and Authorization headers before you log a request. When traits or properties hold personal data, log the record’s IDs instead of the full payload. When you contact your JustAI team about a request, send its messageId, never the key.
