Twofold v2.7

Search pages, sections and endpoints.

    Open the console

    Errors

    The error shape, every code the API can return, and what to retry.

    Environment

    Every endpoint except the two OAuth endpoints returns errors in one shape:

    json
    {
      "error": {
        "type": "invalid_request",
        "code": "invalid_parameters",
        "message": "name is required when creating a patient.",
        "param": "name",
        "requestId": "req_ab12Cd34Ef56"
      }
    }
    json
    {
      "error": {
        "type": "invalid_request",
        "code": "invalid_parameters",
        "message": "name is required when creating a patient.",
        "param": "name",
        "requestId": "req_ab12Cd34Ef56"
      }
    }
    • type is the coarse class, and it determines the HTTP status. Branch on it for retry behavior.
    • code is the specific reason. Branch on it for anything you want to handle individually. New codes can appear within an existing type — treat an unknown one as its type.
    • message is for your logs and for a human reading them. Do not match on it; it can be reworded at any time.
    • param is present when one request field caused the failure.
    • requestId is the same value as the Twofold-Request-Id response header. Quote it when you ask us about a request.

    POST /oauth/token and POST /oauth/revoke return the standard OAuth error body instead — see Authentication. Authentication failures on those routes (missing or wrong credentials, or a Twofold-Client-Id / form client_id disagreement) answer as RFC invalid_client; the Stripe-style code values below are for every other endpoint.

    Error types

    typeHTTPMeaningRetry?
    invalid_request400The request is malformed or the state it asks for is impossible.No — fix the request.
    authentication_error401The credential is missing, wrong, expired or revoked.Only after fixing or refreshing the credential.
    permission_error403The credential is valid but not allowed to do this.No.
    not_found404No such route, or no such object.No.
    rate_limited429Too many requests — see Rate limits.Yes, after Retry-After.
    api_error500Something failed on Twofold's side.Yes, with backoff.

    Error codes

    Partner key authentication

    codetypeWhat happened
    missing_client_idauthentication_errorThe Twofold-Client-Id header is absent.
    missing_api_keyauthentication_errorNo Authorization: Bearer twofold_key_… header.
    invalid_api_keyauthentication_errorThe key does not exist.
    api_key_revokedauthentication_errorThe key was revoked in the console.
    wrong_environment_api_keyauthentication_errorA staging key sent to production, or the reverse.
    client_id_mismatchauthentication_errorThe key is valid but belongs to a different partner than the client id claims.
    partner_not_activatedpermission_errorProduction access has not been opened for your organization yet.

    User token authentication

    codetypeWhat happened
    missing_access_tokenauthentication_errorNo Authorization: Bearer twofold_access_… header.
    invalid_access_tokenauthentication_errorThe token does not exist.
    access_token_expiredauthentication_errorThe token expired, or was rotated by a refresh. Refresh and retry once.
    wrong_environment_access_tokenauthentication_errorA staging token sent to production, or the reverse.
    partner_key_on_user_endpointauthentication_errorA partner API key was sent to a /v2/users/… endpoint, which takes a provider's access token.
    link_revokedpermission_errorThe provider's link has ended. Their data is no longer reachable; send them through consent again.
    external_user_id_mismatchpermission_errorThe {externalUserId} in the path is not the one this token was issued for.

    Requests and resources

    codetypeWhat happened
    invalid_parametersinvalid_requestA path, query or body parameter failed validation. param names the field.
    user_not_foundnot_foundNo currently-linked provider with that externalUserId in your organization.
    request_body_too_largeinvalid_requestThe request body is over the endpoint's size limit. Batch patient upserts take up to 20 MB: send fewer patients per request.
    patient_not_foundnot_foundNo patient with that patientExternalId for this provider.
    note_not_foundnot_foundNo note with that noteId for this provider — or one the API does not serve, see Concepts & identifiers.
    note_deletednot_foundThe note existed and was deleted by the provider. Distinct from note_not_found on purpose: you may hold its id from a webhook.
    route_not_foundnot_foundNo such endpoint — usually a typo or a missing /v2 prefix.
    insufficient_seatsinvalid_requestSetting FULL_ACCESS needs a free seat and none is available. Add seats with set-seats or on the Seats page, or set another provider to READ_ONLY first.
    template_not_foundinvalid_requestA templateIds entry is not one of your organization's base templates (or it is archived). Copy ids from the partner console.
    seats_not_configuredinvalid_requestYour organization has no seat subscription yet — start one on the Seats page, then retry. If that page offers no subscription either, seat pricing is missing on our side: contact Twofold.
    cannot_decrease_seatsinvalid_requesttotalSeats is below your current seat count. Reducing seats changes what you are billed — contact Twofold.
    seat_limit_reachedinvalid_requestThe requested total passes what your current plan covers. Contact Twofold to add seats beyond it.
    annual_term_activeinvalid_requestseat/start with plan: "monthly" for a provider whose paid annual term has not ended. The message carries the term's end date; send plan: "annual" to resume the term at no charge.
    not_available_in_billing_modeinvalid_requestThe endpoint belongs to the other billing mode. On usage billing, access-level and set-seats are replaced by the seat endpoints; on a seat subscription, the seat endpoints are not available. The message names the endpoint to use.
    webhook_url_not_configuredinvalid_requestThe webhook test-fire has no destination: no webhook URL is configured in the console.

    Twofold-side

    codetypeWhat happened
    rate_limit_exceededrate_limitedOver the limit. Wait for Retry-After seconds — see Rate limits.
    temporarily_unavailableapi_errorThe partner API is deliberately paused. Retry with backoff.
    internal_errorapi_errorAn unexpected failure. Retry with backoff; if it persists, send us the requestId.

    Handling failures well

    • Retry only 429 and api_error. Everything else is a decision you have to make, not a condition that clears itself.
    • Use exponential backoff with jitter, and cap the number of attempts. A retry storm against a limit you are already over is the one way to make it worse.
    • Refresh once, then stop. On access_token_expired, refresh and replay the call a single time. If it happens again, the link needs attention, not another refresh.
    • Log requestId on every failure. It is the only handle that lets us find the request in Twofold's logs.