简体   繁体   English

通过 Shopify API 的 PUT 请求的重定向 302

[英]Redirection 302 for PUT request via Shopify API

Set-up设置

I'm using the Shopify Admin API Python library to access our shops via a private app connection.我正在使用Shopify 管理员 API Python 库通过私有应用程序连接访问我们的商店。

GET requests work fine, ie product = shopify.Product.find(6514193137813) retrieves the product data. GET 请求工作正常,即product = shopify.Product.find(6514193137813)检索产品数据。


Issue问题

If I want to update an existing product, PUT requests don't work.如果我想更新现有产品,PUT 请求不起作用。 That is,那是,

product.title = 'test123'
product.save()

returns a Redirection: Response(code=302,...) .返回Redirection: Response(code=302,...)


So far至今

I've double-checked and read and write permission are on.我已经仔细检查并打开了读写权限。

Then I found this question on the Shopify forum: https://community.shopify.com/c/Shopify-APIs-SDKs/API-Fulfillment-Status-Code-302-Redirect/mp/747383/highlight/true# , where Shopify staff member hassain indicates that Shopify prevents you from using HTTP Basic Auth for POST requests that have cookies . Then I found this question on the Shopify forum: https://community.shopify.com/c/Shopify-APIs-SDKs/API-Fulfillment-Status-Code-302-Redirect/mp/747383/highlight/true# , where Shopify 工作人员 hassain 表示Shopify 阻止您使用 HTTP Basic Auth 用于具有 Z55E7DD3016AF14AC7F 的 POST 请求

But since his statement is about POST requests, I'm not sure this is relevant.但由于他的声明是关于 POST 请求的,我不确定这是否相关。

How do I make the PUT request work?如何使 PUT 请求工作?

I followed MalcolmInTheCenter's comment and successfully updated the product using his request code,我关注了 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM