GraphQL - Orders for date range where discountCode is not null

Highlighted
New Member
2 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.
1 Like
Highlighted
Shopify Staff
Shopify Staff
586 71 127

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 

2 Likes
Highlighted
New Member
2 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