draftOrders(first: 10, query:"email:bob.slydell@example.com") does not work

haupham
New Member
3 0 0

I followed a Shopify sample, which is used to "get the first 10 draft orders associated with a customer email"

{
  draftOrders(first: 10, query:"email:bob.slydell@example.com") {
    edges {
      node {
        id
        email
      }
    }
  }
}

haupham_0-1600934407211.png

Therefore, this query should return orders associated with customer email "bob.slydell@example.com". However, the result was strange since it seemed to return all orders regardless order's email. It not only returned orders associated with customer email "bob.slydell@example.com", but also returned orders with other emails like null etc.

People can test it at: https://shopify.dev/docs/admin-api/graphql/reference/object/draftorder#status-2020-07

So is querying with email in DraftOrders broken?

0 Likes
Kevin_A
Shopify Staff
Shopify Staff
317 42 55

Hey @haupham 

If you take a look at our GraphQL query root documentation, you will see that "email" is not a valid field to query on. See here for reference: https://shopify.dev/docs/admin-api/graphql/reference/queryroot

According to that doc, you can filter on a `customer_id`. I will see about getting the invalid query removed from the sample section you pointed out. Thanks for bringing this to our attention. 

Kevin_A | Developer 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

0 Likes
haupham
New Member
3 0 0

So do you mean that I cannot filter DraftOrders based on customer email?

0 Likes
Kevin_A
Shopify Staff
Shopify Staff
317 42 55

Hey @haupham 

You can filter on email for orders, but not for draft orders. If you are able to get the customer ID associated with an email, you can filter based on that ID with draft orders. 

Kevin_A | Developer 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

0 Likes
Jamie_StackUp
New Member
9 0 0

Hello.

I've been looking into this as well, and I have the following query. But this query is returning all draft orders on my store. I'm at a loss and was hoping someone could verify that my query syntax was correct? I've tried various IDs and have also tried wrapping the id in '' so that it's passed through as a string, but still no luck.

Has anyone else had this issue?

 

query {
  draftOrders(first: 12, query: "query=customer_id:4542908498104") {
    edges {
      node {
        id
        customer {
          id
          firstName
          email
        }
      }
    }
  }
}

 

 

0 Likes
Jamie_StackUp
New Member
9 0 0

Okay I have found my mistake, although I'm sure I picked up the original structure from the documentation.

// Correct format
// Notice the change to the value of the query parameter.

query {
  draftOrders(first: 12, query: "customer_id:4542908498104") {
    edges {
      node {
        id
        customer {
          id
          firstName
          email
        }
      }
    }
  }
}

 

I hope this helps anyone who finds it, I came across this post which helped me come to this conclusion https://community.shopify.com/c/Shopify-APIs-SDKs/Syntax-for-quot-query-quot-argument-in-GraphQL-Sto...

0 Likes