Solved

Unable to update order tags via Python requests

mfcss
Explorer
65 6 28

Hi all,

I'm trying to update the "tags" of an order via below code, but I get a 403 error everytime:

def update_shopify_order(API_KEY, API_PASS, SHOP_NAME, order_id):
    # connect to Shopify webshop and get draft orders
    import requests
    import json

    headers = {"Content-Type": "application/json"}
    shop_url = f"https://{API_KEY}:{API_PASS}@{SHOP_NAME}/admin"
    order_url = f"/api/2021-07/orders/{order_id}.json"

    data = json.dumps({"order": {"id": order_id, "tags": "invoice_created"}}).encode("utf-8")

    status = requests.put(shop_url + order_url, timeout=60, data=data, headers=headers)

    return status.status_code

 

Any idea what I might be doing wrong here?

Accepted Solution (1)
mfcss
Explorer
65 6 28

This is an accepted solution.

Update: Now it works - I think maybe updating my permissions for my private app took longer than I expected to kick into effect.

View solution in original post

Replies 3 (3)

Bunty
Shopify Partner
133 39 82

this might be obvious, but I'll ask anyway

  • Is the private app installed on the shop?
  • Does {SHOP_NAME} include .myshopify.com?
  • Does that order exist?

These will be my top reason for when 403 is returned, apart from the wrong key and pass.

mfcss
Explorer
65 6 28

Hi again,

1) I've verified that the connection works by reading that particular order ID via a get request - the order exists

2) I've verified that I've enabled permissions for order editing on my private App

3) I am able to modify other things like pages/products on my webshop via similar style requests (using post, though, instead of put)

My URL looks as follows (sanitized the credentials):

https://XX:XX@shopname.myshopify.com/admin/api/2021-07/orders/3934385897661.json

 

mfcss
Explorer
65 6 28

This is an accepted solution.

Update: Now it works - I think maybe updating my permissions for my private app took longer than I expected to kick into effect.