New Shopify Certification now available: Liquid Storefronts for Theme Developers

Shopify webhook payload delivery type differentiation

Shipday
Shopify Partner
6 0 0

Hi, I have two questions regarding shopify app development.

  1. Our app subscribes to order_create webhook. We need to differentiate between shipping and local delivery from the payload we receive. Which field in the json payload indicates a certain order is shipping or local delivery?
  2. For testing purpose, I have subscribed a webhook with a tunneled https url from ngrok. But I don't receive any webhook data after orders are created. What could be the reason for this?

Thank you

Replies 4 (4)
JeroenB
Shopify Partner
3 0 0

Hi Shipday,

 

As I'm new to the forum, the second thing I am now doing is writing a reply to contribute a bit.

 

In general ngrok is a great tool. If you want to do a quick test if a webhook gets called, I can recommend https://webhook.site as well. You can use those urls as callback url when creating webhooks via the API.

 

> Which field in the json payload indicates a certain order is shipping or local delivery?

 

See https://shopify.dev/api/admin-rest/2022-01/resources/webhook#top , scroll down to Order. That shows the object model for order.

 

Looking at it, I would say take a look at the shipping_lines collection that's in the payload. Each shipping_line has a few related fields that you might want to look at for your data and see how they differ when you compare a shipped item to a local order item.

 

This json snippet is from the url above.

 

JeroenB_0-1644932921948.png

 

 

 

Shipday
Shopify Partner
6 0 0

Thank you for your reply. I tried to deduce a logic from the payload's shipping_lines field. But this field is sometimes empty in some payload. The payload those contain it also have variety of pattern. For example, title field inside shipping_lines can be "local delivery", "Local delivery", "LOCAL DELIVERY" and also many other names which might not suggest it is local delivery order at a glance. Was unable to figure out a specific pattern, that is always followed and will not break my code.

LukeA
Tourist
5 0 1

Hi,

 

I am only new to Shopify API so as far as your first question goes I cant really help. In terms of ngrok though I have run into this issue myself. Part of the issue was the tunnelling that occurred for me was being redirected to a http://localhost:PORT. the application was redirecting internally to the https version. when you start ngrok you need to start it with your https://localhost:PORT link.

 

rather than just running: ngrok http PORT

try: ngrok http https://localhost:PORT

 

which should redirect the tunnelled https query to the correct protocol and allow it to work (at least it did for me)

 

Hope this helps,

 

Luke

JeroenB
Shopify Partner
3 0 0

Also, depending on the type of local webserver you use, you might try this syntax (this is what I use)

 

ngrok http -host-header=rewrite localhost:50189