Adding variant metafields to an order webhook

HamishC
Visitor
3 0 0

Is it possible to add Metafields  with "owner_resource" of the relevant "product" (or "variant")  when creating a webhook driven by the "orders/create" Topic? Am I right in thinking that the fields referenced below would only catch metafields attributed to the order?

 

Thanks!

 

 

HTTP/1.1 201 Created
{
  "webhook": {
    "id": 7226364934,
    "address": "https://example.hostname.com/",
    "topic": "orders/create",
    "created_at": "2022-10-03T13:00:26-04:00",
    "updated_at": "2022-10-03T13:00:26-04:00",
    "format": "json",
    "fields": [
      "id",
      "note"
"variant.MTO"
], "metafield_namespaces": ["global"], "api_version": "unstable", "private_metafield_namespaces": [] } }

 

Reply 1 (1)

HunkyBill
Shopify Expert
4846 60 552

An order has many line items. When your JSON arrives with an order, you can iterate these line items. A Line Item is just another name for a product. A specific variant of a product. Usually, but not always, as with POS you can indeed sell bottles of air with no official product ID or variant ID, but I digress.

Since you have a product at your disposal in your iteration, you are now free to make an API call to get the Metafield resource that interests you assuming it belongs to the product or variant. I am pretty sure that you cannot coerce Shopify to deliver a specific line item Metafield in the JSON payload, but hey! If you can somehow set that up, glory be to you!

TL:DR; you have to do an API call to get your special Metafield per product or variant, once your Webhook payload arrives for your order, and you start iterating your line items.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com