skip to Main Content

I have successfully pulled all orders. However, my goal is to have my task scheduler run my python script to pull yesterday’s or today’s only orders and append the orders to an ongoing master orders list in either a SQL table or excel file. I am thinking it has to be a parameter in the URL but can’t figure it out. Can anyone help with this? below is my python script URL:

date = datetime.today().strftime('%Y-%m-%d')
url = "https://{API}:{Password}@{StoreName}/admin/api/2021-10/orders.json?created_at=" + date + f"&limit=250&status=any&since_id={last}"
response = requests.request("GET", URL)

2

Answers


  1. According to the shopify documentation here about orders you can give 2 parameters:

    created_at_max (Show orders created at or before date.)
    &
    created_at_min (Show orders created at or after date.)

    So if you try these in your setup you should be fine. Example from the docs:

    curl -X GET "https://your-development-store.myshopify.com/admin/api/2021-10/orders.json?updated_at_min=2005-07-31T15%3A57%3A11-04%3A00"
    
    Login or Signup to reply.
  2. I can propose an alternative approach, one that is perhaps less prone to error than your date driven approach. First off, use your script to grab all the orders you can to ensure you are up to date. Process them, do whatever you do with orders. Now, you can easily ensure you have the ID of the latest order processed. Save this value for use!

    Secondly, once a day, at your time of choosing, you run a scheduled job, that grabs all orders SINCE the last ID you previously bootstrapped or saved. That will precisely deliver to you all the orders you have not processed, since you last called this routine (once a day). Parse those orders, save the last ID processed, and continue forever. Note that this is special for the RestAPI. With GraphQL you have other methods that work to generate your lists.

    You can see how this alleviates all the temporal crap of using DateTime objects, which is clearly subject to more WTF moments than anything else we typically do in easy computing.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search