# Query all snps associated with a disease

**URL:** <https://community.opentargets.org/t/query-all-snps-associated-with-a-disease/1004>\
**Category:** GraphQL API\
**Created:** [17 March 2023 19:46 UTC](https://community.opentargets.org/t/query-all-snps-associated-with-a-disease/1004 "2023-03-17T19:46:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![KayK17](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@KayK17](https://community.opentargets.org/u/KayK17)\
**Post date:** [17 March 2023 19:46 UTC](https://community.opentargets.org/t/query-all-snps-associated-with-a-disease/1004/1 "2023-03-17T19:46:15Z")

</div>

I’m not very familiar with coding (I have some history with python) so I’ve been using ChatGPT to try and construct a query to get all snps associated with pregnancy disease in the format  
rsId  
chromosome  
position  
refAllele  
altAllele

The code it suggested is

```python
import requests
import pandas as pd

# set up the Open Targets API endpoint URL
url = 'https://api.opentargets.io/v3/platform/public/evidence/filter'

# set up the query parameters
params = {
    'target': 'EFO_0009682', # set the target to pregnancy disease (EFO ID)
    'datasource': 'evarest', # set the data source to evarest (genetic associations)
    'size': 10000, # set the maximum number of results to return
    'fields': 'variant', # only return variant-level data
    'expandefo': False # don't expand the EFO hierarchy in the response
}

# send the request to the Open Targets API endpoint
response = requests.get(url, params=params)

# extract the relevant data from the response
data = response.json()
results = data['data']

# create a list of dictionaries to store the SNP data
snps = []

# loop through the results and extract the SNP data
for result in results:
    variant = result['variant']
    snp = {
        'rsId': variant['rsid'],
        'chromosome': variant['seq_region_name'],
        'position': variant['start'],
        'refAllele': variant['ref_allele'],
        'altAllele': variant['alt_allele']
    }
    snps.append(snp)

# create a pandas dataframe from the list of SNP dictionaries
df = pd.DataFrame(snps)

# export the SNP data to a CSV file
df.to_csv('pregnancy_disease_snps.csv', index=False)

```

I keep getting an SSL error (and ChatGPT is getting confused) - how do I get the desired output?

---

<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:** [20 March 2023 09:52 UTC](https://community.opentargets.org/t/query-all-snps-associated-with-a-disease/1004/2 "2023-03-20T09:52:39Z")

</div>

Hi @KayK17,

The base urls for our APIs are

- Platform: [https://api.platform.opentargets.org/api/v4/graphql](https://api.platform.opentargets.org/api/v4/graphql)
- Genetics: [https://api.genetics.opentargets.org/graphql](https://api.genetics.opentargets.org/graphql)

The query you posted above will not give you the information you’re looking for. We have a sample query for Python [in our Platform documentation](https://platform-docs.opentargets.org/data-access/graphql-api) and [Genetics documentation](https://genetics-docs.opentargets.org/data-access/graphql-api), which might be good starting points to build a query.
