# GraphQL and API downloads

**URL:** <https://community.opentargets.org/t/graphql-and-api-downloads/1174>\
**Category:** GraphQL API\
**Tags:** datadownloads\
**Created:** [12 August 2023 12:01 UTC](https://community.opentargets.org/t/graphql-and-api-downloads/1174 "2023-08-12T12:01:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Rowen](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/alex_rowen/32/463_2.png) [@Alex\_Rowen](https://community.opentargets.org/u/Alex_Rowen)\
**Post date:** [12 August 2023 12:01 UTC](https://community.opentargets.org/t/graphql-and-api-downloads/1174/1 "2023-08-12T12:01:19Z")

</div>

Dear Community!

A new comer here! I am wondering how one can download data for drug-disease associations?

For example, there is option to access the data via JSON, TSV or API.  
 ![image](https://europe1.discourse-cdn.com/flex017/uploads/opentargets/original/1X/be4516e48b5426f514471bb742a3e3530747754b.png)

GraphQL playground suggests this code to get the data. Obviously, $size variable should be changed to accommodate the complete table download. However, I am not sure how? I tried to find possible solutions in this forum but I am not finding anything that could help me…

I’d really appreciate your advice 🙂

> Blockquote

query KnownDrugsQuery(  
$efoId: String!  
$cursor: String  
$freeTextQuery: String  
$size: Int = 10  
) {  
disease(efoId: $efoId) {  
id  
knownDrugs(cursor: $cursor, freeTextQuery: $freeTextQuery, size: $size) {  
count  
cursor  
rows {  
phase  
status  
urls {  
name  
url  
}  
disease {  
id  
name  
}  
drug {  
id  
name  
mechanismsOfAction {  
rows {  
actionType  
targets {  
id  
}  
}  
}  
}  
urls {  
url  
name  
}  
drugType  
mechanismOfAction  
target {  
id  
approvedName  
approvedSymbol  
}  
}  
}  
}  
}

> Blockquote

---

<div class="post-metadata">

**Author:** ![hcornu](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/hcornu/32/716_2.png) [@hcornu](https://community.opentargets.org/u/hcornu)\
**Post date:** [14 August 2023 09:50 UTC](https://community.opentargets.org/t/graphql-and-api-downloads/1174/2 "2023-08-14T09:50:34Z")

</div>

Hi @Alex_Rowen, and welcome to the Open Targets Community! 🕺

There’s a few ways you can download data for drug-disease associations.

**1. Using the API**

If you copy the code that’s in the API query drawer, the API will return the data in our Known Drugs table. If you change the $size parameter, it should return the number of rows you have specified.

For example, if change it to $size: Int = 1, then I will only get the top row. Please let us know if you’re experiencing issues with this. You can DM me if your query is confidential.

**2. Using the data downloads**

You can download our data directly (see the [Platform documentation](https://platform-docs.opentargets.org/data-access/datasets)). You will find the information on Known Drugs in our Evidence dataset.

I hope this helps! Let me know if you have follow up questions

---

<div class="post-metadata">

**Author:** ![Alex\_Rowen](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/alex_rowen/32/463_2.png) [@Alex\_Rowen](https://community.opentargets.org/u/Alex_Rowen)\
**Post date:** [14 August 2023 10:46 UTC](https://community.opentargets.org/t/graphql-and-api-downloads/1174/3 "2023-08-14T10:46:16Z")

</div>

Thank you very much for your swift response!

I tried changing the $size variable. However, I am not sure what the number for the complete dataset is. It appears that neither the known drug number nor the row number is the right value. There is an additional parameter (counts) - also not entirely sure what that reflects.

Could you maybe explain a bit more how to correctly set the $size parameter to retrieve the full dataset?

Thank you for taking the time to look into my inquiry! 🙂

---

<div class="post-metadata">

**Author:** ![hcornu](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/hcornu/32/716_2.png) [@hcornu](https://community.opentargets.org/u/hcornu)\
**Post date:** [14 August 2023 11:10 UTC](https://community.opentargets.org/t/graphql-and-api-downloads/1174/4 "2023-08-14T11:10:30Z")

</div>

Hi Alex,

You’re welcome!

The count parameter is the number of rows in the table. If you set the size parameter to the same number as the count parameter, then you get the full dataset.

The full dataset given by the API will list the same drug multiple times if it has different sets of clinical trials, which is why the number of rows (counts) is higher than the total number of drugs. Does that make sense?

If you want a list of drugs associated with your disease of interest, you can also download the evidence set, filter for the disease you are interested in, and you will then pick up the list of drugs associated with that disease.

---

<div class="post-metadata">

**Author:** ![Alex\_Rowen](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/alex_rowen/32/463_2.png) [@Alex\_Rowen](https://community.opentargets.org/u/Alex_Rowen)\
**Post date:** [14 August 2023 11:11 UTC](https://community.opentargets.org/t/graphql-and-api-downloads/1174/5 "2023-08-14T11:11:22Z")

</div>

Thank you so much! This is very helpful!
