GraphQL API
The Open Targets Platform GraphQL — available at http://api.platform.opentargets.org — is our new API that allows for language-agnostic access to our data, along with other key benefits:
  1. 1.
    You can construct a query that returns only the fields that you need
  2. 2.
    You can build graphical queries that traverse a data graph through resolvable entities and this reduces the need for multiple queries
  3. 3.
    You can access the GraphQL API playground with built-in documentation and schema showing required and optional parameters
  4. 4.
    You can view the schema that shows the available fields for each object along with a description and data type attribute
  5. 5.
    You only have to use POST requests with a simple query string and variables object
Our GraphQL API supports queries for a single target, disease/phenotype, drug, or target-disease association. For more systematic queries (e.g. for multiple targets), please use our data downloads or our Google BigQuery instance.

Available endpoints

The base URL endpoint for our new GraphQL API is:
1
https://api.platform.opentargets.org/api/v4/graphql
Copied!
You can then access relevant data from the following endpoints:
**/target: **contains annotation information for targets including tractability assessments, mouse phenotype models, and baseline expression; also contains data on diseases and phenotypes association with the given target
**/disease: **contains annotation information for diseases and phenotypes including ontology, known drugs, and clinical signs and symptoms; also contains data on targets associated with the given disease or phenotype
/drug: contains annotation information for compounds and drugs including mechanisms of action, indications, and pharmacovigilance data
/search: contains index of all entities contained within the Platform

Example GraphQL query

Below is an example GraphQL query for AR (ENSG00000169083) that will return Genetic Constraint and Tractability data.
1
query targetInfo {
2
target(ensemblId: "ENSG00000169083") {
3
id
4
approvedSymbol
5
biotype
6
geneticConstraint{
7
constraintType
8
exp
9
obs
10
score
11
oe
12
oeLower
13
oeUpper
14
}
15
tractability{
16
id
17
modality
18
value
19
}
20
}
21
}
Copied!
Using GraphQL's query strings and variables object constructs, you can also access the data using a programming language that supports HTTP POST requests. While this is a valid approach, we discourage users from repeatedly querying the GraphQL API one entity at a time. Instead, our comprehensive datasets available for download provide a simpler and more performant strategy to achieve the same result.

Sample scripts

Below is an example script using the same AR query above, but written for Python and R:
Python
R
1
#!/usr/bin/env python3
2
3
# Import relevant libraries for HTTP request and JSON formatting
4
import requests
5
import json
6
7
# Set gene_id variable
8
gene_id = "ENSG00000169083"
9
10
# Build query string
11
query_string = """
12
query target($ensemblId: String!){
13
target(ensemblId: $ensemblId){
14
id
15
approvedSymbol
16
biotype
17
geneticConstraint {
18
constraintType
19
exp
20
obs
21
score
22
oe
23
oeLower
24
oeUpper
25
}
26
tractability {
27
id
28
modality
29
value
30
}
31
}
32
}
33
"""
34
35
# Set variables object of arguments to be passed to endpoint
36
variables = {"ensemblId": gene_id}
37
38
# Set base URL of GraphQL API endpoint
39
base_url = "https://api.platform.opentargets.org/api/v4/graphql"
40
41
# Perform POST request and check status code of response
42
r = requests.post(base_url, json={"query": query_string, "variables": variables})
43
print(r.status_code)
44
45
# Transform API response into JSON
46
api_response_as_json = json.loads(r.text)
47
48
# Print API response to terminal
49
print(api_response_as_json)
Copied!
1
# Install relevant library for HTTP requests
2
library(httr)
3
4
# Set gene_id variable
5
gene_id <- "ENSG00000169083"
6
7
# Build query string
8
query_string = "
9
query target($ensemblId: String!){
10
target(ensemblId: $ensemblId){
11
id
12
approvedSymbol
13
biotype
14
geneticConstraint {
15
constraintType
16
exp
17
obs
18
score
19
oe
20
oeLower
21
oeUpper
22
}
23
tractability {
24
id
25
modality
26
value
27
}
28
}
29
}
30
"
31
32
# Set base URL of GraphQL API endpoint
33
base_url <- "https://api.platform.opentargets.org/api/v4/graphql"
34
35
# Set variables object of arguments to be passed to endpoint
36
variables <- list("ensemblId" = gene_id)
37
38
# Construct POST request body object with query string and variables
39
post_body <- list(query = query_string, variables = variables)
40
41
# Perform POST request
42
r <- POST(url=base_url, body=post_body, encode='json')
43
44
# Print data to RStudio console
45
print(content(r)$data)
Copied!

Tutorials and how-to guides

For more information on how to use the GraphQL API and example queries based on actual use cases and research questions, check out the Open Targets Community.
Last modified 1mo ago