Search code examples
pythondatetimeshopifyshopify-api

How can I pull only 'yesterday's' orders from Shopify API using Python. Needs to be dynamic, not static


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)

Solution

  • 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"