我正在测试节点shopify-api,我注意到server.js中有一个注册APP_UNINSTALLED web钩子的代码。因此,我添加了下面的代码来尝试接收FULFILLMENTS_UPDATE网络钩子,但是我得到了一个错误。我不确定,但我认为这可能是个错误。
是否可以使用Shopify.Webhooks.Registry.register注册其他webhooks钩子?
const response3 = await Shopify.Webhooks.Registry.register({
shop,
accessToken,
path: "/webhooks",
topic: "FULFILLMENTS_UPDATE",
webhookHandler: async (topic, shop, body) =>{
console.log("FULFILLMENT_UPDATE webhooks", body);
// delete ACTIVE_SHOPIFY_SHOPS[shop]
},
});
if (!response3.success) {
console.log(
`Failed to register APP_UNINSTALLED webhook: ${response.result}`
);
}┃ InternalServerError: Cannot read property 'webhookSubscriptions' of undefined
┃ at Object.throw (/home/user/src/user_test_app/node_modules/koa/lib/context.js:97:11)
┃ at /home/user/src/user_test_app/node_modules/@shopify/koa-shopify-auth/dist/src/auth/index.js:100:42
┃ at step (/home/user/src/user_test_app/node_modules/tslib/tslib.js:133:27)
┃ at Object.throw (/home/user/src/user_test_app/node_modules/tslib/tslib.js:114:57)
┃ at rejected (/home/user/src/user_test_app/node_modules/tslib/tslib.js:105:69)
┃ at processTicksAndRejections (node:internal/process/task_queues:93:5)发布于 2021-03-09 10:22:15
请确保您在所请求的应用范围中添加了read_fulfillments (如果需要的话还添加了write_fulfillments)。
此外,您可以尝试在您的注册中提供一个apiVersion,但不确定它在这种情况下是否有真正的影响。
const registration = await Shopify.Webhooks.Registry.register({
shop,
accessToken,
path: '/webhooks',
topic: 'FULFILLMENTS_UPDATE',
apiVersion: Shopify.Context.API_VERSION,
webhookHandler: async (_topic, shop, _body) => {
// ...
},
})发布于 2021-11-22 05:11:43
我遇到了一个类似的问题,试图注册PRODUCTS_CREATE web钩子主题。我将作用域添加到请求的应用程序作用域,但仍然收到相同的InternalServerError: Cannot read property 'webhookSubscriptions' of undefined。
对我起作用的修正是在注册web钩子主题:时显式地添加所需的作用域。
const response = await Shopify.Webhooks.Registry.register({
shop,
accessToken,
// THE FIX - Add the required scope here
scope: 'read_products',
path: "/webhooks/products/create",
topic: "PRODUCTS_CREATE",
})发布于 2022-05-30 09:22:05
我有类似的东西:error while registering webhooks: TypeError: Cannot read properties of undefined (reading 'webhookSubscriptions'),我添加了我使用的所有作用域,它没有修复它。
因此,我试图用所有我有权添加的范围强制执行,但仍然得到了相同的错误。
原来是webhook主题中的一个拼写错误(INVENTORY_ITEM_CREATE而不是INVENTORY_ITEMS_CREATE),所以如果接受的解决方案不能解决您的问题,我建议您重新检查所有主题名称,因为它会产生类似的错误。
TL;DR:重复检查您的主题名称
https://stackoverflow.com/questions/66539378
复制相似问题