# PheWAS / GWAS lead variants & Tag variants query for multiple snps

**URL:** https://community.opentargets.org/t/phewas-gwas-lead-variants-tag-variants-query-for-multiple-snps/741
**Category:** GraphQL API
**Tags:** genetics-portal
**Created:** [25 August 2022 20:19 UTC](https://community.opentargets.org/t/phewas-gwas-lead-variants-tag-variants-query-for-multiple-snps/741 "2022-08-25T20:19:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![pjordab](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/pjordab/32/160_2.png) [@pjordab](https://community.opentargets.org/u/pjordab)
#### Post date: [25 August 2022 20:19 UTC](https://community.opentargets.org/t/phewas-gwas-lead-variants-tag-variants-query-for-multiple-snps/741/1 "2022-08-25T20:19:37Z")

</div>

Dear Open Targets Team,

First of all thank you very much for this very useful tool, I’m a big fan.

I am trying to query the following tables for multiples snps:

1. PheWAS
2. GWAS lead variants
3. Tag variants

For PheWAS I am using this code in R:

library(httr)  
library(rlist)  
library(dplyr)

# Build query string

query\_string = "  
query PheWASQuery{  
pheWAS($variantId: String!) {  
associations {  
study {  
studyId  
traitReported  
traitCategory  
pmid  
pubDate  
pubAuthor  
source  
}  
pval  
beta  
oddsRatio  
nTotal  
nCases  
eaf  
se  
}  
}  
}"

# Set base URL of GraphQL API endpoint

base\_url ← “[https://api.genetics.opentargets.org/graphql](https://api.genetics.opentargets.org/graphql)”

# Set gene\_id variable

variantId\<-“1\_154453788\_C\_T”

for (i in variantId) {

# Set variables object of arguments to be passed to endpoint

variables ← list(“variantId” = i)

# Construct POST request body object with query string and variables

post\_body ← list(query = query\_string, variables = variables)

# Perform POST request

r ← POST(url=base\_url, body=post\_body, encode=‘json’)

df = content(r)

# Flatten the nested result fields into a dataframe

list\_result = content(r)$data$locations  
x = lapply(list\_result, list.flatten)

result = bind\_rows(x)}

But when I do content(r) I get:

$syntaxError  
[1] “Syntax error while parsing GraphQL query. Invalid input "query PheWASQuery{\n pheWAS($", expected ExecutableDefinition or TypeSystemDefinition (line 2, column 1):\nquery PheWASQuery{\n^”

$locations  
$locations[[1]]  
$locations[[1]]$line  
[1] 2

$locations[[1]]$column  
[1] 1

I’d really appreciate if you could assist me in how to correct my code.  
I also would like to adapt the code to obtain this two other tables:

- GWAS lead variants
- Tag variants

Any help would be much appreciated!! Many thanks!

Paloma

---

<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: [31 August 2022 14:01 UTC](https://community.opentargets.org/t/phewas-gwas-lead-variants-tag-variants-query-for-multiple-snps/741/2 "2022-08-31T14:01:27Z")

</div>

It’s complaining about your query. There are some issues with the structure of the query (e.g. ` studyId` )

You can try to debug the issue using the [GraphQL browser](https://api.genetics.opentargets.org/graphql/browser?)
