简体   繁体   English

我应该在Shopify Rails App中的何处创建卸载Webhooks?

[英]Where in the Shopify Rails App should I create uninstall webhooks?

I'm trying to create an 'app/uninstall' webhook in my Shopify app. 我正在尝试在Shopify应用中创建一个“应用/卸载” webhook。 The app boilerplate was generated using the Shopify API gem( https://github.com/Shopify/shopify_app ), and I've followed the instructions in their readme to the letter. 该应用程序样板是使用Shopify API gem( https://github.com/Shopify/shopify_app )生成的,我按照信中的自述文件中的说明进行操作。

To create these webhooks, I'm assuming they'd have to be somewhere when the client shop first connects with the app - but I'm not sure where exactly that takes place in the whole thing. 为了创建这些webhooks,我假设它们必须在客户端商店首次连接到该应用程序时位于某个位置-但是我不确定整个过程到底发生在哪里。 I've pushed the boilerplate code here: https://github.com/shabbirun/shopify-help-app 我在这里推送了样板代码: https//github.com/shabbirun/shopify-help-app

I first guessed that the code should be in the Shop model, so I tried implementing it using :after_create , but I'm getting an error. 我首先猜测代码应该在Shop模型中,所以我尝试使用:after_create实现它,但出现错误。

Any ideas as to where I can place the code? 关于我可以在哪里放置代码的任何想法?

Thank you! 谢谢!

You will need to post/put a new webhook through the API. 您将需要通过API发布/放置新的Webhook。

Example code is in node: (ruby will be different) 示例代码在node中:(ruby会有所不同)

      shopify.post('/admin/webhooks.json', {
        webhook: {
          topic: 'app/uninstalled',
          address: 'https://yoururl.com/shopify/uninstall',
          format: 'json'
        }
      }, done);

Once the admin webhook has been added, anytime a user uninstalls the app it will hit your api route for shopify uninstalls. 一旦添加了管理员webhook,无论何时用户卸载应用程序,都会点击您的api路线进行shopify卸载。

In terms of placing the code we recommend doing it when a user first approves your app, whichever route that may be. 在放置代码方面,我们建议您在用户首次批准您的应用程序时执行此操作,无论采用哪种方式。

https://docs.shopify.com/api/webhook https://docs.shopify.com/api/webhook

To register a webhook, you can run the add_webhook generator or add a line manually in the shopify_app.rb initializer: 要注册一个Webhook,可以运行add_webhook生成器或在shopify_app.rb初始化程序中手动添加一行:

config.webhooks = [
  {topic: 'app/uninstalled', address: 'https://myapp.url/webhooks/app_uninstalled', format: 'json'},
  {topic: 'orders/create', address: 'https://myapp.url/webhooks/orders_create', format: 'json'},
]

With this setup, your app will register the webhooks automatically when your app gets installed in a shop. 使用此设置,当您的应用程序安装在商店中时,您的应用程序将自动注册webhook。

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

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