# Retrieving \>25 associated drugs

**URL:** <https://community.opentargets.org/t/retrieving-25-associated-drugs/1193>\
**Category:** GraphQL API\
**Created:** [6 September 2023 09:54 UTC](https://community.opentargets.org/t/retrieving-25-associated-drugs/1193 "2023-09-06T09:54:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Myrthe\_Willemsen](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/myrthe_willemsen/32/478_2.png) [@Myrthe\_Willemsen](https://community.opentargets.org/u/Myrthe_Willemsen)\
**Post date:** [6 September 2023 09:54 UTC](https://community.opentargets.org/t/retrieving-25-associated-drugs/1193/1 "2023-09-06T09:54:56Z")

</div>

Hi all!

When querying ‘knownDrugs’ associated to a target, I am able to find at most 25 drugs. Would it be possible to retrieve more associated drugs without using Google Big Query?  
I tried suggestions like `(page: { size: x, index:y })` mentioned [here](https://community.opentargets.org/t/returning-all-associations-data-using-the-platform-api/324/2) and [here](https://community.opentargets.org/t/retrieving-50-pathways-from-evidences/767/2), but they did not work for me.

Many thanks in advance,  
Myrthe

```auto
query search{
  target(ensemblId:"ENSG00000047936"){
      knownDrugs{
      rows{
        drugId
        drug{
          name
        }
      }
      }
  }
}

```

---

<div class="post-metadata">

**Author:** ![ochoa](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/ochoa/32/189_2.png) [@ochoa](https://community.opentargets.org/u/ochoa)\
**Post date:** [6 September 2023 11:26 UTC](https://community.opentargets.org/t/retrieving-25-associated-drugs/1193/2 "2023-09-06T11:26:59Z")

</div>

Have you tried this?

```auto
query q{
  target(ensemblId: "ENSG00000047936"){
    id
    knownDrugs(size: 2){
      count
      rows{
        drug{
          name
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Myrthe\_Willemsen](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/myrthe_willemsen/32/478_2.png) [@Myrthe\_Willemsen](https://community.opentargets.org/u/Myrthe_Willemsen)\
**Post date:** [6 September 2023 11:45 UTC](https://community.opentargets.org/t/retrieving-25-associated-drugs/1193/3 "2023-09-06T11:45:01Z")

</div>

Dear Ochoa,

No, I had not tried that. It works wonderfully, thank you so much!

---

<div class="post-metadata">

**Author:** ![Shicheng\_Guo](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/shicheng_guo/32/217_2.png) [@Shicheng\_Guo](https://community.opentargets.org/u/Shicheng_Guo)\
**Post date:** [16 July 2024 16:32 UTC](https://community.opentargets.org/t/retrieving-25-associated-drugs/1193/4 "2024-07-16T16:32:27Z")

</div>

Could you please provide an updated version of this solution? I am still encountering an error.

```auto

# Load relevant library for HTTP requests
library(httr)

# Set base URL of Genetics Portal GraphQL API endpoint
base_url <- "https://api.genetics.opentargets.org/graphql"

# Additional query to get known drugs for a target
query_drugs <- "
  query q{
    target(ensemblId: \"ENSG00000047936\"){
      id
      knownDrugs(size: 2){
        count
        rows{
          drug{
            name
          }
        }
      }
    }
  }
"

# Construct POST request body object for the drugs query
post_body_drugs <- list(query = query_drugs)

# Perform POST request for drugs query
r_drugs <- POST(url=base_url, body=post_body_drugs, encode='json')

# Check for errors
if (status_code(r_drugs) == 200) {
  # Print known drugs data to RStudio console
  known_drugs <- content(r_drugs, "parsed")$data$target$knownDrugs$rows
  print(known_drugs)
} else {
  print(paste("Error:", status_code(r_drugs)))
}

```

---

<div class="post-metadata">

**Author:** ![Prashant\_Uniyal](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/prashant_uniyal/32/382_2.png) [@Prashant\_Uniyal](https://community.opentargets.org/u/Prashant_Uniyal)\
**Post date:** [17 July 2024 09:24 UTC](https://community.opentargets.org/t/retrieving-25-associated-drugs/1193/5 "2024-07-17T09:24:30Z")

</div>

Hi @Shicheng_Guo ,

I think in your R code, the _base\_url_ is incorrectly pointing to the genetics API whereas the query is on the Platform. It should be changed to

```auto
base_url <- "https://api.platform.opentargets.org/api/v4/graphql"

```

Is there something else that I might be missing? Hope that helps.

Best,  
Prashant
