How do I transform the API response from JSON into a pandas dataframe? I am currently looking for drug targets within Alzheimers, here is the post requests script:
#gene_id = "ENSG00000169083"
disease_ids = ["MONDO_0004975", "EFO_1001870"]
for disease_id in disease_ids:
# Build query string to get general information about AD and knownDrugs and their names and ID's.
query_string = """query getInfoOnAlzheimers ($efoId: String!) {
disease (efoId: $efoId){
id
name
dbXRefs
knownDrugs{
uniqueDrugs
uniqueTargets
rows{
drug{
id
name
tradeNames
}
#name
}
}
}
}
"""
# Set variables object of arguments to be passed to endpoint
variables = {"efoId": disease_id}
# Set base URL of GraphQL API endpoint
base_url = "https://api.platform.opentargets.org/api/v4/graphql"
# Perform POST request and check status code of response
r = requests.post(base_url, json = {"query": query_string, "variables": variables})#, json={"query": query_string, "variables": variables})
print(r.status_code)
#print(r.text)
# Transform API response from JSON into Python dictionary and print in console
api_response = json.loads(r.text)
print(api_response)