Errors
The error shape, every error code with its status and what to do, request ids and which errors are safe to retry.
You will read any error from the API, find its code in a table, and know whether to retry.
The shape#
Every route answers errors in the same shape, a 422 included.
{
"error": {
"code": "invalid_api_key",
"message": "The API key is not valid.",
"request_id": "req-0001"
}
}- Branch on
code, never onmessage. Messages can change. request_idequals theX-Request-Idresponse header. Log it and send it to support.- Ignore codes you do not know. A new code can ship for a new failure without a new version.
Codes#
| Code | Status | Meaning and what to do |
|---|---|---|
bad_request | 400 | The request is malformed or breaks a rule, such as a date range over 60 days. Fix the request. |
bad_request | 409 | Two rolls of a webhook signing secret happened at the same moment. Try again. |
validation_error | 422 | A field is missing or invalid. Fix the field. Do not retry unchanged. |
delivery_not_available | 422 | The vendor does not deliver to the address, or not on that date. Check the zone and the dates. |
product_not_available | 422 | A product is not offered on that date, is not live, or cannot be ordered. Check the catalog. |
order_limits_not_met | 422 | The order is below or above the vendor's limits on items or value. Change the items. |
vendor_not_allowed_for_customer | 422 | The customer's account is limited to certain vendors and this is not one of them. Offer another vendor. |
invalid_time_range | 422 | The open times range is empty, backwards or longer than 31 days. Fix from and to. |
measurement_required | 422 | A first health profile save has no general_health_data. Add it. See Health profiles. |
invalid_api_key | 401 | The key is missing, malformed, unknown, revoked or expired. All look the same. Check the key and header. |
scope_not_granted | 403 | The key lacks the scope the route needs. See Scopes. |
connection_scope_not_granted | 403 | The customer or patient did not approve the connection scope this needs. See Connections. |
company_suspended | 403 | Nurish'd suspended your company. Contact support. |
company_archived | 403 | Nurish'd archived your company. Contact support. |
company_archived | 409 | A customer or patient cannot be created or connected for an archived company. Contact support. |
company_not_live | 403 | A Production key was used before Nurish'd marked the company Live. |
test_mode_only | 403 | A Sandbox test helper was called with a Production key. Use a Sandbox key. |
not_found | 404 | The object does not exist, or it belongs to another company or environment. |
health_profile_not_found | 404 | The patient has no health profile yet. Create it with an update that has general_health_data. |
method_not_allowed | 405 | The route does not allow this HTTP method. |
connection_not_active | 409 | The connection is not active, so the action is refused. Read the connection. |
measurement_too_recent | 409 | The patient has a measurement from the last 24 hours. Send the update without general_health_data. |
webhook_endpoint_limit_reached | 409 | A company has at most 10 webhook endpoints per environment. Delete one first. |
order_conflict | 409 | The order cannot be placed in its current state. Read the customer and the connection, then decide. |
external_id_conflict | 409 | The external_id already belongs to a customer or patient with a different email. Keep using the first id. |
person_already_connected | 409 | The email is already connected under a different external_id. Keep using the first id. |
booking_not_completable | 409 | The test helper was called for a booking that was canceled or is already completed. Use another test booking. |
payment_method_required | 409 | The patient has no card saved, so no visit can be booked. Save one first. See Saving a card. |
payment_method_setup_incomplete | 409 | The card form has not confirmed the card yet. Finish it with Stripe.js, then call confirm again. |
agreements_not_signed | 409 | The patient has not signed the agreements a visit needs. Send them to a fresh connect URL. |
service_not_bookable | 409 | The service cannot be booked online, or the specialist or the service does not exist. Offer another service. |
not_licensed_here | 409 | The specialist cannot serve this booking yet. Offer another specialist. |
slot_taken | 409 | The time is no longer open. Read the open times again. |
booking_not_cancelable | 409 | The booking is already canceled, completed or past. Read the booking. |
rate_limited | 429 | You are over the limit. Wait Retry-After seconds. See Rate limits. |
internal_error | 500 | Something failed on our side. |
upstream_error | 502 | A system we depend on failed. |
upstream_unavailable | 503 | A system we depend on is unavailable. |
upstream_timeout | 504 | A system we depend on took too long. |
Ids#
An id in a path, the vendor query parameter and the order field order_vendor take letters, digits, hyphens, underscores and dots, start with a letter, digit, hyphen or underscore, and have at most 200 characters (^[A-Za-z0-9_-][A-Za-z0-9._-]{0,199}$). An id that does not fit is a 422 validation_error.
Which errors are safe to retry#
| Retry | Codes | How |
|---|---|---|
| Yes, after waiting | rate_limited | Wait Retry-After seconds. |
| Yes, with backoff | upstream_error, upstream_unavailable, upstream_timeout, internal_error | Exponential backoff with jitter, and a cap of a few tries. |
| No | Every other code | The same request fails the same way. Fix it first. |
Retry GET calls freely. Be careful with writes: if a POST to create times out, you may not know whether it worked. For customers and patients, calling create again with the same external_id returns the same one. An order with the same reference, or a booking for the same patient, specialist and start, returns the first one. See Customers, Orders and Booking a visit.
async function call(url, init, tries = 4) {
for (let i = 0; i < tries; i++) {
const res = await fetch(url, init);
if (res.ok) return res;
const retryable = [429, 500, 502, 503, 504].includes(res.status);
if (!retryable || i === tries - 1) {
const body = await res.json().catch(() => ({}));
throw new Error(
`${body.error?.code} request_id=${body.error?.request_id}`,
);
}
const wait = Number(res.headers.get('Retry-After')) || 2 ** i;
await new Promise((r) => setTimeout(r, wait * 1000));
}
}Request ids#
Every answer, success or error, carries X-Request-Id. Error bodies repeat it as request_id. Log it with every failed call. It lets Nurish'd find exactly one call.
Next#
- Rate limits: handle
429well. - Authentication: fix
invalid_api_key. - Support: what to send with a request id.
Something wrong on this page? Email hello@nurishd.io with the page address.