Multiple webhook subscription to a single topic and app

ells-t
Visitor
3 0 1

Hello, 

 

What is the best practice if I have multiple process of my app needing to subscribe to a single topic within the same app. The topic in question is bulk_operations/finish

 

let's say I have:
- process A who uses bulk query with different query parameters

- process B who also uses bulk query with different query parameters 


Is it best practice to just have a single webhook that subscribe and receive all webhook for that topic from Shopify? Or should I register different webhook endpoints for process A and B (this means both endpoints will receive webhook from Shopify?)

If I have a single web hook that receives all the finish query, how can I differentiate between process A and B queries? I just want to know if I just have to do the differentiation myself or if Shopify provides one.

 

 

Replies 2 (2)
ells-t
Visitor
3 0 1

Thank you so much for the quick response Peter! 

For the single webhook endpoint,  Shopify hits this webhook endpoint and provides the payload, how can I have an identifying information? Is there docs you can share? This is actually what I am trying to see if its all possible. 

flareAI
Shopify Partner
2405 223 534

Hello @ells-t,


This is Gina from flareAI app helping Shopify merchants get $6Million+ in sales from Google Search, on autopilot.


If there is a need for multiple processes within a single application to subscribe to a common topic, like "bulk_operations/finish," there are a few possible approaches you can consider.


-> Single webhook endpoint

Instead of having multiple webhook endpoints, you can utilize a single webhook endpoint that subscribes to the "bulk_operations/finish" topic. By doing so, all webhook notifications related to that topic will be received by this endpoint. To distinguish between process A and process B queries, you will need to examine the payload or relevant information within your app logic. By analyzing the received data, you can determine which process the webhook is associated with.


-> Multiple webhook endpoints

Another approach is to register separate webhook endpoints for process A and process B. Each endpoint will independently receive webhook notifications. You can set up one endpoint for process A and another for process B, both subscribing to the "bulk_operations/finish" topic. With this approach, the differentiation is handled at the endpoint level. Each endpoint is dedicated to a specific process, making it easier to manage and keep the logic separate.


The optimal approach depends on your specific requirements. If distinguishing between queries from process A and process B is necessary, it is recommended to register separate webhook endpoints. This allows you to handle the webhooks independently and take distinct actions based on the query source.

 

If differentiation is not required, employing a single webhook endpoint simplifies your code and facilitates management. However, you must devise a method to differentiate between queries within the webhook payload, as Shopify does not offer built-in functionality for this purpose. The responsibility for distinguishing between process A and process B queries lies with your application. You would need to analyze the data received in the webhook payload, such as query parameters or any other relevant information, to determine which process the webhook pertains to.


Consider the following techniques for distinguishing between queries in the webhook payload.


* Utilize the 'id' field in the webhook payload, which is unique for each bulk operation. You can leverage this identifier to determine the originating process.

* Inspect the 'query_params' field in the webhook payload, which contains the query parameters employed in the bulk operation. This information can help identify the process responsible for the query.

* Combine both the 'id' and 'query_params' fields for the most accurate differentiation between queries. This approach provides a comprehensive means of identifying the query source.

The choice between a single webhook endpoint or multiple endpoints depends on your app's specific requirements and how you prefer to organize and manage the webhook processing logic within your app.


I hope this information proves useful.


Gina

flareAI : Get Sales from Google Search, on Autopilot
$10+ billion in eCommerce on Google Search, every day. Find out how much you are missing