Shopify API返回401 Unauthorized - Ruby on Rails

时间:2017-02-27 15:51:37

标签: ruby-on-rails shopify

我已经创建了shopify合作伙伴应用。应用程序与商店成功连接。之后我在'orders / updated'上创建了webhook。以下代码在webhook回调中,但Shopify API返回401 Unauzhorized。

url = request.headers['x-shopify-shop-domain'] # shop url
token = request.filtered_parameters["token"] # token from header
session = ShopifyAPI::Session.new(url, token) # create session
ShopifyAPI::Base.activate_session(session)
shop = ShopifyAPI::Shop.current # returns 401 Unauthorized

错误如下:

ActiveResource::UnauthorizedAccess (Failed.  Response code = 401.  Response message = Unauthorized.)

1 个答案:

答案 0 :(得分:0)

您似乎跳过了关于验证webhook的整个部分。为确保您不会受到垃圾的破坏,您需要按照此处列出的步骤处理您的传入数据:https://help.shopify.com/api/getting-started/webhooks#verify-webhook