GraphQL - Orders for date range where discountCode is not null

Highlighted
Tourist
3 0 1
Hello,
 
Using the GraphQL API, I'd like to get a list of orders for a date range, where the discountCode property is not null. Here's my query which I'm testing with using the Shopify GraphiQL App:
 
{
orders(first: 5, query:"created_at:>=2020-03-02 AND created_at:<2020-03-03 AND discountCode:*")
  {
edges
    {
      node{
        id
        discountCode
      }
}
  }
}
 
Here's the (slightly redacted) result:
 
{
  "data": {
    "orders": {
      "edges": [
        {
          "node": {
            "id": "gid://shopify/Order/22...54",
            "discountCode": null
          }
        },
        {
          "node": {
            "id": "gid://shopify/Order/22...38",
            "discountCode": null
          }
        },
        {
          "node": {
            "id": "gid://shopify/Order/22...54",
            "discountCode": null
          }
        },
        {
          "node": {
            "id": "gid://shopify/Order/22...22",
            "discountCode": "6G...KX"
          }
        },
        {
          "node": {
            "id": "gid://shopify/Order/22...90",
            "discountCode": "AT...7Q"
          }
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 7,
      "actualQueryCost": 7,
      "throttleStatus": {
        "maximumAvailable": 2000,
        "currentlyAvailable": 1993,
        "restoreRate": 100
      }
    }
  }
}
 
3 of my 5 results contain a NULL discountCode. According to this link, I should be able to match non-NULL values using the "*":
 
Am I doing something wrong? Is what I'm attempting even possible?
 
Thanks for any guidance.
Highlighted
Shopify Staff
Shopify Staff
644 78 141

Hey @cwineman,

 

Thanks for bringing this up. I've tested on my end and have been able to replicate the behaviour you've described. I've raised the issue with our developers for further investigation. As soon as I have an update to share, I will post here to let you know.

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

Highlighted
Tourist
3 0 1

Thanks for the reply.

 

I do notice now that I used the property discountCode instead of what probably should have been discount_code in the filter. However, it still didn't solve the problem. I still received results with null discount codes.

 

I suspect the problem is that discountCode simply isn't a property you can filter by. If that is the case, It would be nice if there were an error to let me know that.

0 Likes
Highlighted
New Member
1 0 0

"This query can be combined with a Not Query to find fields missing a value, e.g. -published_at:*" (https://shopify.dev/concepts/about-apis/search-syntax)

You must have just forgotten the "-" before "discount_code"

0 Likes
Highlighted
Tourist
3 0 1

Thanks for the response. 

I'm not trying to find null discount codes if that's what you were thinking. I'm specifically trying to find non-null discount codes. But the "*" referenced in that link doesn't seem to be working, and orders with null discount values are coming back.

 

*edited to fix typo

0 Likes