Errors
When a request fails, data is null and errors says why. Branch on the HTTP status and the code. The text is for a person and may be reworded.
What an error looks like
This login has an action Flit does not know:
curl -s -X POST "$FLIT/api/v1/applications/$APP/audit-authentication" \
-H "Authorization: Bearer $KEY" \
-H 'Content-Type: application/json' \
-d '{
"id": "login_9001",
"client_id": "user_42",
"action": "signin"
}'const response = await fetch(`${process.env.FLIT}/api/v1/applications/${process.env.APP}/audit-authentication`, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
"id": "login_9001",
"client_id": "user_42",
"action": "signin"
}),
});
const { data, errors } = await response.json();import os
import requests
response = requests.post(
f"{os.environ['FLIT']}/api/v1/applications/{os.environ['APP']}/audit-authentication",
headers={"Authorization": f"Bearer {os.environ['KEY']}"},
json={
"id": "login_9001",
"client_id": "user_42",
"action": "signin",
},
)
data = response.json()["data"]{
"data": null,
"errors": [
{
"code": "in_choices",
"path": "action",
"context": {
"choices": [
"login",
"login_failed",
"password_reset_requested",
"password_reset_completed",
"password_change",
"email_change",
"phone_change",
"two_factor_enabled",
"two_factor_disabled",
"new_device_login"
]
},
"text": "Must be one of the available choices"
}
]
}| Field | What it tells you |
|---|---|
code | What went wrong, as a stable word. |
path | The field of your request it is about, or null when it is about the request as a whole. |
context | The detail: the allowed values, the longest length, the limit you hit. |
text | A sentence for a log. |
A request with several things wrong gets several errors at once, one for each field.
By status
| Status | Code | What happened |
|---|---|---|
| 400 | a validation code, with a path | A field is missing, the wrong kind, too long, or not one of the allowed values. |
| 400 | parse_error | The body is not a JSON object. |
| 400 | app_ref_exist | There is no application with the id in the URL. Unknown ids are a 400 here, not a 404. |
| 401 | unauthenticated | No Authorization header. |
| 401 | invalid_credentials | The key is unknown, mistyped or revoked, or a sign-in token has expired. |
| 403 | forbidden | The key is real, but not for this application: most often a test key sent to the live id. Also an API key used where only a signed-in person may act, such as creating keys. |
| 403 | policy_loosening_forbidden | A key tried to relax a policy. A person has to. |
| 404 | not_found | No such endpoint. |
| 409 | various | The thing is not in a state for that: a trip already released, the limit of test applications reached. |
| 413 | body_too_large | The request is over 1 MB. |
| 429 | rate_limit_exceeded | Too many requests. See below. |
| 429 | sandbox_quota_exceeded | Test mode's daily limit is used up. |
| 500 | server_error | Flit failed. Treat it as no decision. |
| 503 | service_unavailable | Flit cannot reach something it needs. Treat it as no decision. |
Validation codes you will meet
| Code | Meaning |
|---|---|
in_choices | Not one of the allowed values, which are listed in context.choices. |
dense_string | Must be text with something in it. The event's id and client_id. |
too_long | Longer than context.max_length. |
void_or_decimal | Must be a number, or left out. |
void_or_ip_address | Not an IP address. |
currency_code | Not a three-letter currency code. |
uuid | An id in the URL is not a UUID. |
A validation error means no decision was made and nothing was recorded. Fix the request; sending it again unchanged gets the same answer.
Rate limits
Limits are counted per calling address, which for decisions is your server's, over a sliding minute.
| Requests | Limit |
|---|---|
Decisions (audit-…) | 1,000 a minute. Raised on request for live applications. |
| Everything else under an application or organization | 100 a minute. |
Signing in and tokens (/auth/…) | 5 a minute, then refused for five minutes. |
| Signing up | 5 an hour. |
Every answer carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset, so you can slow down before you are told to. A 429 carries Retry-After, in seconds.
{"ok": false, "errors": [{"code", "message", "context"}]}, with no data and message in place of text. Read the status and Retry-After, and do not rely on the body.Request ids
Every answer has an X-Request-Id header. Log it. If you send your own X-Request-Id, of up to 64 letters, digits and . _ : -, Flit uses yours, so one id follows the request through both systems. Quote it, or a decision's audit_id, when you write to support.