# Retrieving orders using Python requests.get

**URL:** <https://community.shopify.com/t/retrieving-orders-using-python-requests-get/238853>\
**Category:** Shopify Apps\
**Tags:** third-party-apps\
**Created:** [August 6, 2023, 2:50pm UTC](https://community.shopify.com/t/retrieving-orders-using-python-requests-get/238853 "2023-08-06T14:50:47Z")\
**Posts on this page:** 3\
**Page:** 1

## AI-generated summary

A developer encountered a 401 authentication error when attempting to retrieve Shopify orders using Python's `requests.get()` method, despite having a working API admin key verified through the Shopify Python library.

**Initial Problem:**
- Successfully authenticated using `shopify.Session` and `shopify.ShopifyResource.activate_session()`
- Failed when switching to direct HTTP requests with `requests.get()`, receiving 401 errors

**Resolution:**
- Issue was incorrect authentication token formatting in the request headers
- **Working solution:** Pass headers as `{'X-Shopify-Access-Token': api_admin, 'Content-Type': 'application/json'}` to `requests.get(url, headers=headers)`
- Updated API version from 2023-04 to 2023-07 in the final working code

**Status:** Resolved - developer self-identified the authentication header issue and confirmed the corrected approach works without errors.

<div class="post-metadata">

**Author:** ![Velor-cycling](https://avatars.discourse-cdn.com/v4/letter/v/67e7ee/32.png) [@Velor-cycling](https://community.shopify.com/u/Velor-cycling)\
**Post date:** [August 6, 2023, 2:50pm UTC](https://community.shopify.com/t/retrieving-orders-using-python-requests-get/238853/1 "2023-08-06T14:50:47Z")

</div>

Hi,

I’m trying to retrieve orders from my Shopify webshop using Python.

I set up the app in the admin page and retrieved API admin key. I verified that the key works because the following code is allowing me to get order information.

api\_session = shopify.Session(shop\_url, ‘2023-01’, api\_admin)  
shopify.ShopifyResource.activate\_session(api\_session)

However, the following code is giving me a 401 error. Can someone explain what I am doing wrong?

hostname=‘[my-shop.myshopify.com](http://my-shop.myshopify.com)’  
url = [email removed]  
response = requests.request(“GET”, url)  
print(response)

Thanks!

---

<div class="post-metadata">

**Author:** ![Velor-cycling](https://avatars.discourse-cdn.com/v4/letter/v/67e7ee/32.png) [@Velor-cycling](https://community.shopify.com/u/Velor-cycling)\
**Post date:** [August 6, 2023, 3:20pm UTC](https://community.shopify.com/t/retrieving-orders-using-python-requests-get/238853/2 "2023-08-06T15:20:28Z")

</div>

Same thing if I try this:

url=‘[https://my-shop.myshopify.com/admin/api/2023-04/orders.json?status=any](https://my-shop.myshopify.com/admin/api/2023-04/orders.json?status=any)’  
headers = {‘X-Shopify-Access-Token’: api\_admin}  
response = requests.get(url, headers)  
print(response)

any pointers as to what I’m doing wrong are welcome!

---

<div class="post-metadata">

**Author:** ![Velor-cycling](https://avatars.discourse-cdn.com/v4/letter/v/67e7ee/32.png) [@Velor-cycling](https://community.shopify.com/u/Velor-cycling)\
**Post date:** [August 7, 2023, 7:14am UTC](https://community.shopify.com/t/retrieving-orders-using-python-requests-get/238853/3 "2023-08-07T07:14:00Z")

</div>

OK I did something wrong passing the authentication token to the requests.get command.

This seems to be working now, no error 401:

url=‘[https://my-shop.myshopify.com/admin/api/2023-07/orders.json?status=any](https://my-shop.myshopify.com/admin/api/2023-07/orders.json?status=any)’  
headers = {‘X-Shopify-Access-Token’: api\_admin, ‘Content-Type’: ‘application/json’}  
response = requests.get(url, headers=headers)
