Bulk Delete Test Orders Through Shopify API

Bulk Delete Test Orders Through Shopify API

KlaviyoJad
Shopify Partner
2 0 1

I have already looked at the solution here and running a script like here using the APIs:

 

 

 

import requests

url = 'https://{api_key}:{api_password}@corseta-republic.myshopify.com/admin/api/2022-04/orders.json?status=closed&limit=50'
response = requests.get(url.format(api_key=api_key,api_password=password))

while response.status_code == 200:
    orders = response.json()
    for order in orders['orders']:
        print(f'deleting order {order["name"]}')
        requests.delete(f"https://{api_key}:{password}@corseta-republic.myshopify.com/admin/api/2022-04/orders/{order['id']}.json")
    response = requests.get(url.format(api_key=api_key,api_password=password))
    print(response.status_code)

 

 

 

 

only problem is that at some point the call to 'https://{api_key}:{api_password}@corseta-republic.myshopify.com/admin/api/2022-04/orders.json?status=closed&l...' returns a 500 because there are no more archived orders.

Initially I selected everything I wanted to delete which is orders before 

03/08/2022 but performing the following actions in the Shopify Admin UI:

 

KlaviyoJad_0-1667495863092.png

 

The operation does not seem to archive everything I want it to so find myself repeatedly going to the UI archiving all and then re-running the Python script.  Is there a more seamless way of achieving this?  This has been going on for 3 weeks since archiving operation in the UI seems to do very little.

 

 

 

 

 

Replies 0 (0)