组织
我正在使用Shopify Admin API Python库通过专用应用程序连接访问我们的商店。
GET请求工作正常,即Products=shop ify。Product.find(6514193137813)
检索产品数据。
问题
如果我想更新现有产品,PUT请求不起作用。就是,
product.title = 'test123'
product.save()
返回一个重定向:响应(code=302,...)
。
到目前为止
我已经仔细检查,读写权限已打开。
然后我在Shopify论坛上发现了这个问题:https://community.shopify.com/c/Shopify-APIs-SDKs/API-Fulfillment-Status-Code-302-Redirect/m-p/747383/highlight/true#,Shopify的工作人员hassain指出Shopify阻止您使用HTTP Basic Auth处理具有Cookie的POST请求。
但由于他的声明是关于POST请求的,我不确定这是否相关。
如何使PUT请求工作?
我跟随MalcolmInTheCenter的评论,使用他的请求代码成功地更新了产品,
import requests
payload = {
"product":{
"title":"My new title"
}
}
api_key = "xxxxx"
password="xxxxxx"
headers = {"Accept": "application/json", "Content-Type": "application/json"}
#send email to customer through events endpoint
r = requests.put("https://"+api_key+":"+password+"@MYSTORE.myshopify.com//admin/api/2021-01/products/{PRODUCT_ID}.json", json=payload, headers=headers)
print(r)