What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Order/update Webhook does not contain metafields

Order/update Webhook does not contain metafields

Timothy3
Shopify Partner
4 0 0

Per the Webhook API documentation:

metafield_namespaces: Optional array of namespaces for any metafields that should be included with each webhook.

This seems to work for product and customer Webhooks, but not for order Webhooks.  Is this working for anyone, or is this a defect in the Shopify Webhook code?

I have confirmed that the order/update Webhook was created with the desired metafield namespace, and have also confirmed the metafield data is present on the updated order.  When the order is updated, the Webhook fires with the complete order data, but the metafields are omitted.  Why?

Any help or guidance is appreciated!

Replies 13 (13)

_JCC_
Shopify Staff
200 27 56

@Timothy3 ,

Happy to help you out with this issue.

Would you be able provide a recent example of an order id where an update was made in the last twelve days and the meta-fields were not present in the web hook payload. With the order id I can do some further investigation on our end.

Regards,

Johnn

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Timothy3
Shopify Partner
4 0 0
Hi Johnn,

I updated orderId 2979111796810 just now, and still see the same problem.
Please let me know what you find.
_JCC_
Shopify Staff
200 27 56

@Timothy3 ,

Had a look and discovered there's two orders/update web hook subscriptions for the store associated with the order provided.

Each webhook is posting to a unique endpoint, with one subscription including meta-field namespaces and the other not. I believe the one not including meta-fields is the subscription created under Settings, Notifications in the Shopify Admin.

I will follow-up with a DM to share the URL endpoints and which has the meta-field namespace turned on for it's subscription.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Filljoy
Shopify Partner
211 10 67

@_JCC_ I am running into the same issue with orders/create. I have both metafields_namespaces as well as private_metafields_namespaces for my webhook (ID 1017668960420). When the order object comes through, I don't see any of this information - am I not understanding how this is supposed to work? An example order ID is 3674395115684. Thank you. 

_JCC_
Shopify Staff
200 27 56

Hey @Filljoy,

For the order provided there's no metafields on the order record itself. The order would need to have metafield values for the namespace specified in your web hook subscription.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Filljoy
Shopify Partner
211 10 67

Thanks @_JCC_ for the quick response. I think I must have been confused as to how this is supposed to work. I believe my use case is similar to this: https://community.shopify.com/c/Shopify-APIs-SDKs/Webhook-metafield-namespace-how-to-use/m-p/334721

In each order object that comes through to my endpoint, I'd like to determine the app that created the webhook subscription (as I have some merchants who have installed multiple of my apps, and I am processing orders through a single shared endpoint which I just realized is causing duplication that I didn't account for). 

It seems I don't quite grasp Shopify metafields, can you please walk me through how the namespace metafield feature is supposed to actually work and the use case for this?

And separately,  is there a way to attach a metafield to a POS order using App Bridge (without doing so using the API after the fact)?  Thank you.

_JCC_
Shopify Staff
200 27 56

Metafields are a way for developers, partners, and merchants to extend the data stored with a given resource type, in this case an order resource. Here's a GraphQL tutorial providing some examples. 

When you create a web hook subscription for an Order resource and list metafield_namespaces, you're asking us to include the additional data you might be storing on an order resource via metafields. If the order in question has no metafields for the namespace you've indicated in the web hook subscription, nothing will be delivered.

On the point about determining the app the web hook subscription came from. There's a possibility that a web hook for a given resource like an order is delivered more than once, and we include a header X-Shopify-Webhook-Id to help app developers identify duplicates. The value of header is tied to the orders state, and the app that registered the web hook. When you create the web hook subscription you could specify something in the url to help identify the app it originated from.

Sorry I'm not sure about using metafields in App Bridge, but I feel that if you want to extend an order with a metafield, I think the receipt of the orders/create web hook would be ideal for this.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Filljoy
Shopify Partner
211 10 67

Thanks @_JCC_  for the explanation. In my case I have a couple apps where I need to perform similar back-end operations after an order is created, so I'm sending them to the same orders/create endpoint, which is causing me trouble. In examining this more closely, there's no easy way using X-Shopify-Webhook-Id to infer which app / api key it's coming from, is that right? 

_JCC_
Shopify Staff
200 27 56

Now it's a little clear what you mean :-). No, the X-Shopify-Webhook-Id could not be used to infer the app it originated from. If you have two distinct apps sending web hooks to the same server the only thought I had was updating the subscription so that the url has information contained within it for you to determine the app the web hook payload is associated with.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Filljoy
Shopify Partner
211 10 67

Thanks a lot John, very helpful. I'm going with your approach to just break things up into individual endpoints. Much appreciated!

ClementBR
Shopify Partner
161 2 51

@_JCC_ thanks for the useful info.

Is it possible when subscribing to a webhook to ask for the inclusion of metafields for ALL namespaces?

_JCC_
Shopify Staff
200 27 56

Hey @ClementBR ,

Presently there's no ALL namespaces option on creation or update of a web hook subscription. I will be sure to share this request with the web hooks team.

Regards,

John

John C | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

amit-flyy-dev
Shopify Partner
2 0 0

Hey Timothy, I had the same problem of webhooks and metafield, I wanted to send some private metafields when a customer is created. Since you mentioned that it works for you for the customer webhooks,
I really need to know how should I set up the metafields so I can receive them on my webhooks.

 

Currently I am subscribing the webhooks with the partner_secret_key namespace with these mutation in GraphQL

    query = `mutation($input: PrivateMetafieldInput!) {
        privateMetafieldUpsert(input: $input) {
          privateMetafield {
            namespace
            key
            value
            valueType
          }
          userErrors {
            field
            message
          }
        }
      }`
    metafields_values = {
        "input": {
            "namespace": "partner_secret_keys",
            "key": "my_secret",
            "valueInput": {
              "value": "SOMEKEY",
              "valueType": "STRING"
            }
        }
    }