Python client for strorefront graphql API

Highlighted
New Member
1 0 0

Hi,

I am trying to build python client for storefront graphql API. I have tested the query using curl api.

curl -X POST https://mondayblues.myshopify.com/api/2019-07/graphql \
    -H 'X-Shopify-Storefront-Access-Token: ee466cb2b7130d7e2f3477e31b41194c' \
    -H 'Content-Type: application/graphql' \
    -H 'Accept: application/json' \
    -d ' {
  collections(first: 10) {
    edges {
      node {
        products(first: 10) {
          edges {
            node {
              description
              title
            }
          }
        }
      }
    }
  }
}
'

This gets the data with HTTP status code 200.

 

When I hit the same API with python client I get HTTP Status 403 with no response.

Do you have any sample client? Am I missing anything in the call?

 

import requests
import json

access_token = "ee466cb2b7130d7e2f3477e31b41194c"
url = "https://mondayblues.myshopify.com/api/2019-07/graphql"

collecctions_query = '''query {
  collections(first: 10) {
    edges {
      node {
        products(first: 10) {
          edges {
            node {
              description
              title
            }
          }
        }
      }
    }
  }
}'''


headers = {
    "X-Shopify-Access-Token": access_token,
    "Content-Type": "application/graphql",
    "Accept": "application/json"
    }


if __name__ == "__main__":
    # data={"query": collecctions_query}
    res = requests.post(url, json={"query": collecctions_query}, headers=headers)
    result = res.text
    print(result)

Thanks,

Mallik

 

 

 

0 Likes