A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi,
I'm trying to retrieve all Draft Orders for a given Customer. My query is defined as:
query GetDraftOrders($query: String!) {
draftOrders(first: 250, query: $query) {
nodes {
id
customer {
id
}
}
}
}
Passing the following for $query:
customer_id:gid://shopify/Customer/XXXXXXXXXXXXX
Omitting query from the query parameters yields all Draft Orders, and has results where the customer.id value matches the GID being used when attempting to filter the results.
I've also tried wrapping the GID in the query string in single quotes with no success:
customer_id:'gid://shopify/Customer/XXXXXXXXXXXXX'
Is there something I'm missing? Seems like it should work based on the draftOrders page in the docs, and I've managed to use the query parameter successfully for other queries (e.g. retrieving Products by product_type via the Storefront API).
API Version is 2022-04.
Any help would be appreciated, thanks!
Solved! Go to the solution
This is an accepted solution.
Managed to figure this out myself, customer_id is only expecting the numerical portion of the Customer GID.
So to query Draft Orders for the following Customer GID:
gid://shopify/Customer/1234567898765
The query string should be:
customer_id:1234567898765
Kind of confusing, because when querying for single Order objects, the GID is passed as the ID parameter for the query, and the customer.id on the Order object is the full GID.
Hopefully this helps someone else, should apply to any queries that are being filtered using things like product_id, customer_id, order_id, etc.
This is an accepted solution.
Managed to figure this out myself, customer_id is only expecting the numerical portion of the Customer GID.
So to query Draft Orders for the following Customer GID:
gid://shopify/Customer/1234567898765
The query string should be:
customer_id:1234567898765
Kind of confusing, because when querying for single Order objects, the GID is passed as the ID parameter for the query, and the customer.id on the Order object is the full GID.
Hopefully this helps someone else, should apply to any queries that are being filtered using things like product_id, customer_id, order_id, etc.