Веб-перехватчики в shopify / shopify-api с использованием nodejs

Я тестировал узел shopify-api и заметил, что в server.js есть код, который регистрирует веб-перехватчик APP_UNINSTALLED. поэтому я добавил приведенный ниже код, чтобы попытаться получить веб-перехватчик FULFILLMENTS_UPDATE, но получаю сообщение об ошибке. Я не уверен, но думаю, что это может быть ошибка.

Можно ли зарегистрировать другие веб-перехватчики с помощью Shopify.Webhooks.Registry.register?

        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)




person Johnathan David    schedule 09.03.2021    source источник
comment
Я проверил на этой странице shopify.dev/docs/admin-api/graphql / reference / events /, что тема WebhookSubscriptionTopic FULFILLMENTS_UPDATE существует, но я не могу ее зарегистрировать.   -  person Johnathan David    schedule 09.03.2021
comment
Сообщество . shopify.com/c/Shopify-APIs-SDKs/ Я задал тот же вопрос в сообществе shopify.   -  person Johnathan David    schedule 09.03.2021


Ответы (1)


Убедитесь, что вы добавили read_fulfillmentswrite_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) => {
        // ...
    },
})
person Aurélien B.    schedule 09.03.2021
comment
Я действительно забыл добавить область read_fulfillments. Я сделал, и это сработало. Спасибо! - person Johnathan David; 09.03.2021