Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Saving Webhook payload to state or global variable

Saving Webhook payload to state or global variable

Alternatives
New Member
9 0 0

We setup basic shopify Node/React app and registered the orders/create webhook. How can save the payload to a global variable or state and how do we access it in the app? We want to trigger a function when we recieve the webhook. Any help is appreciated.

 

const ordersCreate = await Shopify.Webhooks.Registry.register({
          shop,
          accessToken,
          path: "/webhooks",
          topic: "ORDERS_CREATE",
          webhookHandler: async (topic, shop, body) =>
            console.log(body)
            
        });

//process the webhoooks
router.post("/webhooks", async (ctx) => {
    try {
      await Shopify.Webhooks.Registry.process(ctx.req, ctx.res);
      console.log(`Webhook processed, returned status code 200`);
      //console.log(ctx.res);
    } catch (error) {
      console.log(`Failed to process webhook: ${error}`);
    }
  });

 

Replies 0 (0)