Search code examples
node.jsshopifyshopify-app

Shopify Webhook Real Time changing


is there an api on shopify where I can see real time when data changes ? Maybe I have a node server and I use sockets to see when anyone has bought anything from my shop that I get a notification via nodejs on my backend. is it possible ? a few websites has this, they offers you to sell on their site and you can see real time changes data when anything was bought


Solution

  • Yes, you can subscribe to multiple Webhooks to get notified when a change occurs on your shop. Using the REST Admin API, available webhook event topics include:

    • orders/create: occurs whenever an order is created / someone buys from your shop.
    • orders/paid: occurs whenever an order is paid.
    • orders/fulfilled: occurs whenever an order is fulfilled.
    • orders/cancelled: occurs whenever an order is cancelled.

    Use the /admin/api/2023-01/webhooks.json endpoint to subscribe to a webhook:

    // Node.js - Session is built by the OAuth process
    const webhook = new shopify.rest.Webhook({session: session});
    webhook.topic = "orders/create";
    webhook.address = "https://example.hostname.com/";
    // format you want to receive the event data in 
    webhook.format = "json"; // or XML
    // fields you want to receive
    webhook.fields = [
      "id",
      "note"
    ];
    await webhook.save({
      update: true,
    });
    

    You can also use the GraphQL Admin API for the same purpose.