Webhook registration in Node JS, how?

cajmorgan
New Member
4 0 2

Hello everyone!

I'm a new app developer on Shopify and are using the Shopify node create command to build the apps. One of the most challenging things have been the lack of documentation to actually implement the features, especially in Node. The last step I'm on now is to implement webhooks. The folder structure when using the Shopify CLI command is as follows: server -> server.js, index.js, handlers -> client.js, index.js, mutations -> (mutations with graphQL). In the server.js file I understand one webhook gets created here 

const response = await Shopify.Webhooks.Registry.register({
          shop,
          accessToken,
          path: "/webhooks",
          topic: "APP_UNINSTALLED",
          webhookHandler: async (topic, shop, body) =>
            delete ACTIVE_SHOPIFY_SHOPS[shop],
        });

        if (!response.success) {
          console.log(
            `Failed to register APP_UNINSTALLED webhook: ${response.result}`
          );
        }

So I understand that webhookHandler is what activates the webhook when it sends, but how do I make another webhook that links correctly to a new graphql query?  

Let's say I export this function I found in the mutations folder -> 

export const getOneTimeUrl = async (ctx) => {
  const { client } = ctx;
  const confirmationUrl = await client
    .mutate({
      mutation: ONETIME_CREATE(process.env.HOST),
    })
    .then((response) => response.data.appPurchaseOneTimeCreate.confirmationUrl);
  return ctx.redirect(confirmationUrl);
};

 should I import and pass that function in the webhookHandler with the ctx argument?

Any help would be appreciated.

Also, are there updated docs of these that I just haven't found? I can only find deprecated ones on GitHub, but I mean c'mon, if that's the case then this is getting ridiculous in how badly documented this process is. If I'm in the wrong here, please guide me and I will be forever grateful! 

Replies 0 (0)