'Can Orders be filtered by metafield using the Shopify API?

There's no mention of this capability on the Shopify API Docs Page, but I'm wondering if anyone may have experience with an undocumented means of doing this.

Edit for further explanation: The idyllic imaginary solution would be something like GET /admin/orders.json?metafield[metafield_key]=metafield_value.



Solution 1:[1]

The problem with this approach is pretty easy to figure out. An order is a resource. Metafields are also a resource. You never get an orders's metafields when you ask for the order resource using the API. So now you're stuck making an API call for each orders metafield resources.

So your filter will be slow. Same problem makes using variant metafields bad, as you need to make an API call to get them, hence any scripting relying on them will never be real-time fast but always O(N) slow...

As @alex mentions, you could use your own DB to filter... so that answer is the only one that makes any sense for any App needing to work WWW.

Solution 2:[2]

Assuming you can add metafields to Shopify orders:

   PUT /admin/orders/#{id}.json
{
 "order": {
"id": 450789469,
"metafields": [
  {
    "key": "new",
    "value": "newvalue",
    "value_type": "string",
    "namespace": "global"
  }
]
}
}

You can definitely store the orders in a database and then filter them by metafields.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ryan M
Solution 2 alexandresaiz