What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

GraphQL variables not working when getting order by name

GraphQL variables not working when getting order by name

PurpleMamba
Shopify Partner
126 1 18

I'm trying to look up an order by name, this is my code

 

 # Get an order by order name field
  query = ShopifyAPI::GraphQL.client.parse <<-'GRAPHQL'
    query($query: String) {
      orders(first: 1, query: $query) {
        edges {
          node {
            id
            name
            createdAt
          }
        }
      }
    }  
  GRAPHQL

  variables = {
    query: "name:2456"
  }

  result = ShopifyAPI::GraphQL.client.query(query)

 

It should return the order passed in the variables, but instead returns the very first order in the database.

What am I doing wrong here?

Replies 2 (2)

HunkyBill
Shopify Partner
4853 60 568

You need to wrap your name in single quotes to get that to work.

{
	"query": "name:'Test#1234'"
}

Works for me perfect.

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
PurpleMamba
Shopify Partner
126 1 18

Hi @HunkyBill thanks for answering!

I tried that, and it didn't change the result unfortunately. Still not getting back the queried order.