Solved

Filtering draftOrders query by customer_id

madetogether
Shopify Partner
2 1 1

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!

Accepted Solution (1)

madetogether
Shopify Partner
2 1 1

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_idcustomer_idorder_id, etc.

View solution in original post

Reply 1 (1)

madetogether
Shopify Partner
2 1 1

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_idcustomer_idorder_id, etc.