无法从 Shopify Webhook 中找到数据/有效负载

概括

我一直在关注关于使用 Node 和 React 设置应用程序的 Shopify 教程。我一切正常,但我正试图越过最后一步。我正在尝试获取从 Shopify webhooks 返回的数据,但我看不到数据/有效负载的位置。


背景

我已经尝试在中间件之前和之后打印出响应和请求,但似乎没有得到任何有用的回报,只是收到如下内容:


{ method: 'POST',

  url: '/webhooks/products/create',

  header:

   { host: '01e9702c.ngrok.io',

     'user-agent': 'Shopify-Captain-Hook',

     'content-length': '1175',

     accept: '*/*',

     'accept-encoding': 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',

     'content-type': 'application/json',

     'x-shopify-api-version': '2019-07',

     'x-shopify-hmac-sha256': 'some value',

     'x-shopify-product-id': '2018829729858',

     'x-shopify-shop-domain': 'example.myshopify.com',

     'x-shopify-topic': 'products/create',

     connection: 'close',

     'x-forwarded-proto': 'https',

     'x-forwarded-for': '123.456.789' } }


  router.post('/webhooks/products/create', webhook, (ctx) => {

    console.log('Products webhook - create: ', ctx.state.webhook);

    // Want to view product that was created here

  });


  router.post('/webhooks/products/delete', webhook, (ctx, x) => {

    console.log('Products webhook - delete: ', ctx.state.webhook);

    // Want to see product that was deleted here

  });


胡说叔叔
浏览 318回答 2
2回答

慕标琳琳

你使用的网络框架是什么?是快递吗?添加 webhook 的代码会有所帮助,但现在您的签名已关闭。请在此处查看我的回答Nodejs - Expressjs - 验证 shopify webhook以了解如何使用正文解析器的验证方法。然后你的钩子处理程序看起来像:router.post('/webhooks/products/create', (req, res)=>{    console.log(JSON.stringify(req.body, null, ' '));    res.sendStatus(200);    // process the webhook});

德玛西亚99

看起来您正在使用基本节点/反应示例中的 Koa 框架。假设您已经找到它,但是任何人都在寻找,答案是ctx.state.webhook.payload您可以从那里访问各个元素,因此 ctx.state.webhook.payload.title也可以使用。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript