Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Admin API ResourceNotFound error when trying to mark order as fulfilled.

Admin API ResourceNotFound error when trying to mark order as fulfilled.

baby_step_books
Tourist
5 0 1

I am trying to automatically mark a handful of orders as fulfilled. This code worked a couple weeks ago, but the last few times I have tried it it's throwing a pyactiveresource.connection.ResourceNotFound error. As if the order_id doesn't exist. I am using the python helper library, and have made sure it's up to date. I've also tried playing around with different api versions, but that hasn't changed anything for me. Here is my code:

 

 

import shopify

api_version = '2022-10'
shop_url = "shop_name.myshopify.com"
access_token = "my_access_token"
session = shopify.Session(shop_url, api_version, access_token)
shopify.ShopifyResource.activate_session(session)
location_id = shopify.Location.find()[0].id # my fulfillment location.


uid = "#SH38069"
order_list = shopify.Order.find(name=uid)
order = order_list[0]

fulfillment = shopify.Fulfillment({
                  'order_id':order.id,
                  'line_items':order.line_items,
                  'location_id':location_id
                })

fulfillment.save()

 

And the error I am getting:

pyactiveresource.connection.ResourceNotFound: Not Found: https://my_store.myshopify.com/admin/api/2022-10/orders/5291045159162/fulfillments.json

I have also tried hitting the rest api without the python shopify package:

import requests
headers = {
    "X-Shopify-Access-Token": access_token,
    "Content-Type": "application/json"
}
order_list_url = f"{shop_url}/admin/api/{api_version}/orders.json?name={urllib.parse.quote(uid)}"
response = requests.get(order_list_url, headers=headers)
response.raise_for_status()  # This will raise an error if the request failed
orders = response.json()['orders']
order = order_list[0]
fulfillment_url = f"{shop_url}/admin/api/{api_version}/orders/{order['id']}/fulfillments.json"
fulfillment_data = {
    "fulfillment": {
        "location_id": location_id,
        "line_items": [{"id": item['id']} for item in order['line_items']]
    }
}
response = requests.post(fulfillment_url, headers=headers, json=fulfillment_data)
if response.status_code == 201:
    print(uid)
    return True
else:
    print(uid, "Couldn't Save", response.status_code) # Got a 404.
    return False

And I'm getting the same 404 error. I'm not sure where to go from here as I was using this snippet regularly a month ago without issue, and all of a sudden things stopped working.

Thanks!

Replies 0 (0)