Skip to main content

Making Authenticated Requests

Every request to the FHIR GraphQL API carries two things: a bearer token identifying the caller, and a project header identifying whose data the request is for. Both are required, and both are checked.

Required headers​

HeaderValue
AuthorizationBearer <jwt>
X-Project-IDYour project_uid — see below
Content-Typeapplication/json
POST /graphql
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
X-Project-ID: 3fa85f64-5717-4562-b3fc-2c963f66afa6
Content-Type: application/json

/health and /metadata are the only endpoints that answer without an X-Project-ID header; both are public and serve no project data. CORS preflight (OPTIONS) requests are also exempt.

What goes in X-Project-ID​

Despite the header's name, its value is your project_uid — the external project identifier, a UUID. It is the value the projects API returns as id, and the value shown as the project id in the dashboard. Both refer to the same thing.

It is never a numeric database id. If you are integrating against a MedBackend API that returns an integer alongside a project, that integer is internal and will not work here. Sending one is rejected with 400 INVALID_PROJECT_UID.

Some older projects have a short text project_uid (for example acme-corp) rather than a UUID. Both forms are valid; send whichever your project has, verbatim. The value is case-insensitive and is normalised to lowercase.

Project headers you may encounter​

HeaderStatusValue
X-Project-IDCurrent. Send this.project_uid
X-Project-UIDDeprecated. Still accepted by the management API, logs a warning. Do not use in new integrations.project_uid
X-MedBackend-Project-UIDInternal. Set by MedBackend when forwarding to agent endpoints; never sent by clients.project_uid

All three carry the same value. Only the first is part of the supported client contract.

A first request​

curl -X POST https://backbone.medbackend.com/graphql \
-H "Authorization: Bearer $TOKEN" \
-H "X-Project-ID: $PROJECT_ID" \
-H "Content-Type: application/json" \
-d '{"query": "query { Me { reference } }"}'
const response = await fetch("https://backbone.medbackend.com/graphql", {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"X-Project-ID": projectId,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query { Me { reference } }`,
}),
});

const { data } = await response.json();
console.log(data.Me.reference); // "Practitioner/def456"
import requests

response = requests.post(
"https://backbone.medbackend.com/graphql",
headers={
"Authorization": f"Bearer {token}",
"X-Project-ID": project_id,
"Content-Type": "application/json",
},
json={"query": "query { Me { reference } }"},
)

print(response.json()["data"]["Me"]["reference"])

Confirm which identity you resolved to​

Me returns the FHIR reference your token maps to. It is the quickest way to check that your credentials are set up correctly, and every authenticated caller can read it.

query {
Me {
reference
}
}
{
"data": {
"Me": {
"reference": "Practitioner/def456"
}
}
}

reference is the only field. If it comes back null, your token is missing one or both identity claims, and every other request will be denied. Start there before debugging anything else — a null here explains an entire session of unexplained denials.

Passing variables​

Queries take variables the usual way:

const query = `
query GetPatient($id: ID!) {
Patient(id: $id) {
name { given family }
birthDate
}
}
`;

const response = await fetch("https://backbone.medbackend.com/graphql", {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"X-Project-ID": projectId,
"Content-Type": "application/json",
},
body: JSON.stringify({
query,
variables: { id: "3fa85f64-5717-4562-b3fc-2c963f66afa6" },
}),
});

The project binding​

A valid token on its own does not reach a project's data. The project is named in two independent places and both must agree:

  • the X-Project-ID header, which selects whose configuration and whose data the request is served from
  • the project_uid claim inside the token, recording the project the token was issued for

If they disagree, the request is refused. A token issued for one project cannot be pointed at another by changing the header.

This boundary fails closed. When the check cannot be performed at all, that counts as a failure rather than a pass — there is no path where a missing or unverifiable binding results in access.

Successful responses echo the resolved project back in an X-Project-ID response header, which is useful when tracing a request through your own logs.

Caller roles​

The identity your token resolves to determines which validation rules apply. Four types are meaningful:

TypeTypical caller
PatientA patient using a portal or app
PractitionerA clinician
RelatedPersonA parent, guardian or carer acting for a patient
DeviceEquipment, workers, integrations, AI models

What each may actually do is entirely a matter of the project's validation rules. There are no built-in per-role permissions — see Validation, and Requiring a Practitioner Role for narrowing a rule to clinicians holding a specific role.

Token lifetimes​

TokenLifetime
User token1 hour
Device token5 minutes by default

There is no revocation list, which is why the lifetimes are short. If a credential is compromised, expiry is your revocation window — plan your response around that rather than around a revoke call.

Errors​

ResponseMeaning
400 MISSING_PROJECT_UIDX-Project-ID header absent
400 INVALID_PROJECT_UIDHeader present but malformed
404 PROJECT_NOT_FOUNDNo such project
503 CONFIG_SECTION_INVALIDThe project's configuration is missing a required section; the response names it
503 CONFIG_UNAVAILABLEConfiguration temporarily unavailable
Project mismatchToken and header name different projects
Access denied naming a role and resourceAuthenticated successfully; no rule grants this operation

That last row is the one to read carefully. A denial naming your role and the resource type is an authorization failure — your token was fine. Check the project's rules for that role / resource / operation combination. With the default policy, no matching rule means no access.