New Shopify Certification now available: Liquid Storefronts for Theme Developers

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)