Orders - GraphQL query fore retrieving all orders created in a given start and end date time range

Orders - GraphQL query for retrieving all orders with Paid status created in a given start and end date time range

For example, GraphlQL query to get all the orders with status ‘Paid’ from startDateTime 2023-11-06T10:00:00Z to endDateTime 2023-11-06T10:30:00Z

I have tried with below query which is throwing error:

GraphQL Query:

query orderIds($created_at: String)
{orders(createdAt:$created_at){
id
}
}

GraphQl Variable:

{
“created_at”: [“and”,“>=2023-10-11T00:00:00Z”, “<2023-10-13T06:40:55Z”]
}

But receiving error

“message”: “Field ‘orders’ doesn’t accept argument ‘createdAt’”

In Shopify’s GraphQL API, the orders query does not directly accept a createdAt argument. Instead, you should be filtering orders using the query argument with the appropriate search terms. Here’s how you can modify your query to retrieve orders that have been paid within a specific date and time range:

{
  orders(first:100, query: "financial_status:paid AND created_at:>='2023-11-06T10:00:00Z' AND created_at:<='2023-11-06T10:30:00Z'") {
    edges {
      node {
        id
        createdAt
        fullyPaid
      }
    }
  }
}
1 Like

Thanks for the quick response, Lee. Much appreciated.

Query works as expected.

Can you please say, is there any way to query the Orders by updated date only? I mean, to fill the date and get all of the orders from a specified date by one request? How can I avoid the cursor and first/last values? I have some solution when the cursor’s value is passed to the query via loop, by using the cursor value from a previous query.

This is what I use bit wan to change.

query GetOrders($qty: Int, $continueFrom: String)

    orders(first: $qty, after: $continueFrom, reverse: false, query:"created_at:>2023-10-01T20:00:00")

Thank You, for help.