通过 API 创建 Shopify Webhook 时出错 [英] Error Creating Shopify Webhook through the API

查看:67
本文介绍了通过 API 创建 Shopify Webhook 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 API 创建一个 Webhook.当客户安装应用(控制器)时:

I am trying to create a Webhook through the API. When the Customer installs the app (Controller):

def init_webhooks
  topics = ["products/create", "products/update", "products/delete"]
  topics.each do |topic|
    webhook = ShopifyAPI::Webhook.create(format: "json", topic: topic, address: "http://#{@current_host}/webhooks/#{topic}")
    raise "Webhook invalid: (#{topic}) #{webhook.errors}" unless webhook.valid?
  end
end

这是日志中的错误:

RuntimeError (Webhook invalid: (products/create) #<ActiveResource::Errors:0x00000003bd7358>):

我什至尝试过只创建一个没有块代码的 webhook,如下所示:

I have even tried just creating one webhook without the block code like so:

webhook = ShopifyAPI::Webhook.create topic: "products/create", address: "http://myapp.com/webhooks/products/create", format: "json"

但我得到了同样的东西.

But I get the same thing.

来自我的路由文件:

  match 'webhooks/products/create' => 'webhook#product_new'
  match 'webhooks/products/update' => 'webhook#product_updated'
  match 'webhooks/products/delete' => 'webhook#product_deleted'

我知道授权和商店实际上是正确安装的,因为如果我注释掉Raise"错误行,我就会进入索引页面,其中显示了我在 Shopify 管理中创建的一些测试订单和测试产品.

I know that the authorization and shop is in fact installing correctly because if I Comment out the 'Raise' error line, I then proceed to the index page which displays some test orders and test products that I created within the Shopify Admin.

我不知道从哪里开始.谢谢

I'm not sure where to go from here. Thanks b

推荐答案

你使用的参数 (topic,format,address) 看看对我很好,但不应该是 ShopifyAPI::Webhook.new 而不是 create 吗?

The params you use (topic,format,address) look good to me, but shouldn't it be ShopifyAPI::Webhook.new instead of create?

您现在有可以轻松测试 ruby​​ 代码的 shopify 控制台吗?

Did you now there is a shopify console where you can easily test your ruby code?

这篇关于通过 API 创建 Shopify Webhook 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆