New Shopify Certification now available: Liquid Storefronts for Theme Developers

Filter an order via GET by using flags or note_attributes

rpfeil
Visitor
1 0 0

Hi,

i am currently importing orders using REST, once imported I am marking them as imported by updating them with a flag and a note attribute.

Now I am trying to only GET the orders that don't have my flag/note attribute set.

 

How can I set the Parameter in my GET so that those orders get ignored?

Replies 2 (2)
Jayvin
Shopify Partner
284 42 89

Hi,

Well, I don't think there is any order api request that let's you filter orders by flag/note attribute.

What you can do is a combination of filters like created_at_min, created_at_max, since_id etc into your order request to filter out the orders that you have already imported.

https://shopify.dev/docs/admin-api/rest/reference/orders/order?api[version]=2020-07

banned
Gregarican
Shopify Partner
1033 86 282

For defining flags I typically use tags, as opposed to the note field. Since you can have multiple tags, and the note field is a one-shot deal. 

Here's a GraphQL example where I am pulling the 5 most recent orders that don't have imported defined in the tag values. The minus sign in the query specifies that I don't want the tag value to be imported. Should work fine!

{
  orders(first: 5, reverse: true, query: "-tag:imported") {
    edges {
      node {
        id
        name
        note
        tags
      }
    }
  }
}