API

A GraphQL based API (Application Programming Interface) can be used to query the HLA Serotype Database.

How GraphQL APIs Work

Your App

GraphQL Query

GraphQL API

JSON Response

Serotype Data

An API (Application Programming Interface) defines a set of rules and protocols that enable different software applications to interact with one another. GraphQL is a query language designed for APIs that not only lets you retrieve data but also lets you specify exactly which data fields should be returned. This targeted approach ensures you obtain precisely the information you need in an efficient manner.

API Endpoint

https://serotype.org/api/graphql

Header (key:value)

x-api-key:

YOUR_API_KEY

Response size cap

Fetching bulk data in R or curl

The getDownloads query returns a files array enumerating every pre-built file with its scope, locus, resolution, format, and a ready-to-use url. Export files are research use only: filenames carry a RESEARCH_USE_ONLY_ prefix and a random suffix and cannot be guessed — pick the row you want and fetch its url(don't build paths by hand). The same list is on the Downloads page.

# R — pull bulk full-field for the current version (research use only)
library(httr); library(jsonlite)
key <- Sys.getenv("SEROTYPE_API_KEY")
q <- 'query { getDownloads { version files { url scope resolution format } } }'
res <- POST("https://serotype.org/api/graphql",
            add_headers(.headers = c("x-api-key" = key)),
            body = list(query = q), encode = "json")
files <- fromJSON(content(res, "text", encoding = "UTF-8"))$data$getDownloads$files
row <- subset(files, scope == "bulk" & resolution == "full_field" & format == "json")
df <- jsonlite::fromJSON(gzcon(url(row$url)))
cat("rows:", nrow(df), "\n")
# curl — discover the file URL, then download it
URL=$(curl -s https://serotype.org/api/graphql \
  -H "x-api-key: $SEROTYPE_API_KEY" -H 'content-type: application/json' \
  -d '{"query":"{ getDownloads { files { url scope resolution format } } }"}' \
  | jq -r '.data.getDownloads.files[] | select(.scope=="bulk" and .resolution=="full_field" and .format=="json") | .url')
curl -sL "$URL" | gunzip -c | jq 'length'

See lesson 3 for a walk-through of all three patterns for bulk data (query narrowing, cap-error handling, manifest-driven discovery).

Parameters

loci
[String!]
alleles
[String!]
allele_exact_match
Boolean
= true
serotypes
[String!]
scores
[String!]
split_antigens
[String!]
broad_antigens
[String!]
bw4_bw6
[String!]
resolution
Resolution
= two_field
accepts values: two_field or full_field

Response

locus
String
allele
String
score
String
score_code
String
score_description
String
serotype
String
split_antigen
String
broad_antigen
String
ciwd
String
cwd
String
eurcwd
String
bw4_bw6
String
version
String

Example Query

query {
  alleleToSerotype(
    alleles: ["A*02:01"]
    resolution: two_field
  ) {
    locus
    allele
    score
    score_code
    score_description
    serotype
    split_antigen
    broad_antigen
    bw4_bw6
    ciwd
    cwd
    eurcwd
    version
  }
}

Example Response

{
  "data": {
    "alleleToSerotype": [
      {
        "locus": "A",
        "allele": "A*02:01",
        "score": "Full",
        "score_code": "F",
        "score_description": "Matches the serotype's reference pattern at every defining residue.",
        "serotype": "A0201",
        "split_antigen": "A2",
        "broad_antigen": "A2",
        "bw4_bw6": "",
        "ciwd": "C",
        "cwd": "C",
        "eurcwd": "C",
        "version": "1.0"
      }
    ]
  }
}

See the API in action using interactive tools that can generate the GraphQL query and return the results. Try it now

Learn how to use the API with interactive R examples at our learning portal