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
| Header | Value |
|---|---|
Authorization | Bearer <jwt> |
X-Project-ID | Your project_uid — see below |
Content-Type | application/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
| Header | Status | Value |
|---|---|---|
X-Project-ID | Current. Send this. | project_uid |
X-Project-UID | Deprecated. Still accepted by the management API, logs a warning. Do not use in new integrations. | project_uid |
X-MedBackend-Project-UID | Internal. 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-IDheader, which selects whose configuration and whose data the request is served from - the
project_uidclaim 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:
| Type | Typical caller |
|---|---|
Patient | A patient using a portal or app |
Practitioner | A clinician |
RelatedPerson | A parent, guardian or carer acting for a patient |
Device | Equipment, 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
| Token | Lifetime |
|---|---|
| User token | 1 hour |
| Device token | 5 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
| Response | Meaning |
|---|---|
400 MISSING_PROJECT_UID | X-Project-ID header absent |
400 INVALID_PROJECT_UID | Header present but malformed |
404 PROJECT_NOT_FOUND | No such project |
503 CONFIG_SECTION_INVALID | The project's configuration is missing a required section; the response names it |
503 CONFIG_UNAVAILABLE | Configuration temporarily unavailable |
| Project mismatch | Token and header name different projects |
| Access denied naming a role and resource | Authenticated 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.
Related
- Identity providers — connecting your OAuth provider
- Device authentication — non-interactive callers
- Requiring a Practitioner Role — restricting a rule to a specific clinical role
- Validation — writing the rules that decide access