I am trying to create simple orders using Shopify Admin REST api but after 3rd POST request it throws 429 status code, too many requests error. However, when trying with other entities such as Products, Collections, Customers and etc. everything works fine. After a lot of research still can't find the answer.
X-Shopify-Shop-Api-Call-Limit
always return 1/40
Even when I put sleep
between requests the same error appears after 4th or 5th request. I am really stuck at this point.
Here is the code that I am trying:
import requests
headers = {"X-Shopify-Access-Token": "shppa_password"}
data = {
"order": {
"line_items": [
{
"variant_id": 40313388007584,
"quantity": 1
}
]
}
}
for i in range(7):
res = requests.post("https://MYSHOP.myshopify.com/admin/api/2021-04/orders.json", headers=headers, json=data)
print(res.status_code)
print(res.headers['X-Shopify-Shop-Api-Call-Limit'])
You need a deliberate delay in the loop. Shopify can't handle rapid requests, it needs a delay of at least 2 seconds between each one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.