New Shopify Certification now available: Liquid Storefronts for Theme Developers

Query Orders Where Created at Falls within A Certain Range

tamara_mcd
Shopify Partner
3 0 0

 

query ($cursor: String, $query: String!, $lineItemsCursor: String) {
      orders(first: 5, sortKey: CREATED_AT, query: $query, after: $cursor) {
        pageInfo {
          hasNextPage
        }
        edges {
          cursor
          node {
            id
            createdAt
            lineItems(first: 50, after: $lineItemsCursor) {
              pageInfo {
                hasNextPage
              }
              edges {
                cursor
                node {
                  id
                  quantity
                  variant {
                    id
                    displayName
                    sku
                    inventoryQuantity
                  }
                }
              }
            }
          }
        }
      }
    }

 

Above is the query I am using to query orders using GQL. It works when I set the `query` string to "created_at:>=2022-01-01" but when I try "created_at:>=2022-01-01 and created_at:<=2022-01-31" I get 0 results. Any insight into what I am doing wrong with the query string would be helpful.

Reply 1 (1)
Alan
Shopify Staff
Shopify Staff
129 15 23

Hey @tamara_mcd can you try a query using this syntax and let us know if it works? Removing the sortKey param may work:


orders(first:20, query:"created_at:>2019-12-05T10:10:10Z created_at:<2021-12-09T12:12:12Z") 

 I was able to test a similar query using this syntax and it pulled orders created between the requested dates in the response. 

Hope this helps! 

Alan | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog