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.

Re: How to configure orders/update webhook to include metafields?

Solved

How to configure orders/update webhook to include metafields?

alan-forme
Visitor
2 0 2

I'm trying to establish a webhook so that my backend is notified of metafield updates associated with my orders.

To start I created a webhook with id 1032526397617, it looks like this:

        {
            "id": 1032526397617,
            "address": "https://REDACTED/path",
            "topic": "orders/updated",
            "created_at": "2021-05-07T12:26:04-04:00",
            "updated_at": "2021-05-07T12:26:04-04:00",
            "format": "json",
            "fields": [
                "id",
                "updated_at",
                "order_number"
            ],
            "metafield_namespaces": [
                "global"
            ],
            "api_version": "2021-04",
            "private_metafield_namespaces": []
        }

 

I do receive events on that endpoint when metafields in the "global" namespace are added/updated, but the payload does not include the metafields themselves.

Instead I just receive something like:

{
    "id":3876848500913,
    "order_number":1037,
    "updated_at":"2021-05-07T12:36:53-04:00"
}

I find it interesting that the webhook does not even include an empty "metafields" array.

If I query the order directly, I see my metafields are indeed present and part of the "global" namespace:

curl 'https://REDACTED.myshopify.com/admin/api/2021-04/orders/3876848500913/metafields.json'

{
  "metafields": [
    {
      "id": 19278238417073,
      "namespace": "global",
      "key": "wallType",
      "value": "0",
      "value_type": "string",
      "description": null,
      "owner_id": 3876848500913,
      "created_at": "2021-05-07T12:36:53-04:00",
      "updated_at": "2021-05-07T12:36:53-04:00",
      "owner_resource": "order",
      "admin_graphql_api_id": "gid://shopify/Metafield/19278238417073"
    },
    /// ...
  ]
}

 

After reading and re-reading the documentation, I tried using a different metafield namespace on the off-chance that "global" is reserved, but I I still receive a payload without any metafields.

Accepted Solution (1)

swalkinshaw
Shopify Staff
20 4 12

This is an accepted solution.

The payload is determined by the `fields` attribute you've set on the webhook subscription. So even though you set `metafield_namespaces`, you still need to include `metafields` in your `fields otherwise they won't be included in the payload.

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 2 (2)

swalkinshaw
Shopify Staff
20 4 12

This is an accepted solution.

The payload is determined by the `fields` attribute you've set on the webhook subscription. So even though you set `metafield_namespaces`, you still need to include `metafields` in your `fields otherwise they won't be included in the payload.

To learn more visit the Shopify Help Center or the Community Blog.

alan-forme
Visitor
2 0 2

Confirmed. Working now.

You are my hero.

Thank you so much!