I wanted to know if there is any way to query orders based on the ClosedAt date.
Hi SRCB,
This should be possible, eg: if you want to query orders where closedAt date is before Jan 1st 2024, your query would look like:
query OrdersClosedBefore {
orders(first: 10, query: "closed_at:<2024-01-01") {
edges {
node {
id
closedAt
name
totalPriceSet {
shopMoney {
amount
currencyCode
}
}
}
}
}
}
I tested the above in my dev store and it returned orders as expected where closedAt date was before Jan 1st 2024.
Hope this helps!
Thank you.
It’s not documented here so if it’s meant to work, I think it should be added to the documentation. I feel like if it’s not documented it’s not fully supported, which means it can be broken without notice.
Actually I just tested it. It’s returning all orders, not only ones that were closed before Jan 1st 2024. @Liam-Shopify
Could you share the entire GraphQL query @SRCB ?
The search syntax can be finicky.
When I search by date fields, I noticed I have to wrap the date fields in single quotes sometimes for the operators to filter properly:
orders(query:"created_at:>='2024-01-01' AND shippingAddress:*") {
edges {
node {
id
}
}
}
That query above searches for all orders created after the Jan 1st 2024 and have a shipping address (not digital products).
But the same single quote wrapping might help in your case.
This is the full query.
query OrdersClosedBefore {
orders(first: 10, query: "closed_at:>=2024-01-01") {
edges {
node {
id
closedAt
name
totalPriceSet {
shopMoney {
amount
currencyCode
}
}
}
}
}
}
When I swap out closed_at for created_at, it works as expected. I already tried using single quotes replacing the query string with this. closed_at:>='2024-01-01'
It didn’t help.