ShopifyQL vs GraphQL

Highlighted
New Member
22 0 0

I would like to produce a simple report each month with the following columns.

  Date, Time, Discount Code, Country, State, City, Zip Code

where there is one entry for each order and the discount code may possibly be null (i.e., no discount was applied). Eventually I may want to add additional columns, such as order price. I also want to export the data in CSV format.

Should I use ShopifyQL or GraphQL for this? Are there any examples with a discount code?

0 Likes
Shopify Staff
Shopify Staff
135 6 29

Hey David,

Zameer here from the Shopify Developer Experience team.

If that's all the information you are looking for, I would recommend that you use the GraphQL API as all of that information lives on the Order object, and can be retrieved in a single query. 

Your query would look something like:

{
  orders(first: 10) {
    edges {
      node {
        id
        createdAt
        discountCode
        billingAddress{
          country
          province
          city
          zip
        }
      }
    }
  }
}

You would then have to implement pagination using the `after` or `before` argument as specified in the order documentation.

0 Likes
New Member
22 0 0

Can you give a simple example of before and after since the orders documentation is not very clear?

How would a date range such as December or last month or yesterday or between 2 dates, etc. be specified instead of the first 10 orders?

0 Likes
Shopify Partner
1531 109 307

That would look something like

orders(first: 10, query:"created_at='2018-12-5T15:05:12Z'")

Spoiler alert... greater than, less than, ranges don't work a.k.a. totally useless for date based filtering. Who'd filter by exact dates is beyond me?

If someone knows of a way to do this I'd be curious too.

Regards

I turn coffee in to code - since 1998
0 Likes
New Member
22 0 0

I would like to know the orders on a specific date or range of dates, such as on 2018-12-04 or between 2018-11-01 and 2018-11-30. Does anyone know how to do this with GraphQL?

0 Likes
Shopify Staff
Shopify Staff
135 6 29

Hey David,

You should be able to do this with the syntax that Karl mentioned. You will still have to declare either a 'first' or 'last' parameter, but you can then also include as a query your date range. For example, to retrieve all orders made between November 1st and 31st (inclusive) you would call:

  orders(first: 10, query:"created_at:>2018-11-01 created_at:<2018-11-31")

I would recommend taking a look at the orderConnection documentation, which shows all the possible query values you can use. As well as the search syntax documentation, which shows you how to construct your queries.

2 Likes
Shopify Partner
1531 109 307

Ooooh... how sweet is that!

Zameer Masjedee you just made my day. Thanks!

I turn coffee in to code - since 1998
1 Like
New Member
22 0 0

Thanks, but the search syntax documentation has no date examples.

For November (inclusive), would I use :> with :< or :>= with :<=? In addition, do I need to use AND or is this implied?

0 Likes
Shopify Staff
Shopify Staff
135 6 29

Hey David,

The "AND" is implied with the 'space' between the two arguments in the query. 

For dates, it seems that both :> and :< operators are inclusive without the need to insert the equal sign as well. 

0 Likes
New Member
22 0 0

Thank you.

We are just setting up a store and are trying to create reports and get ready. Is there any test data that can be used with GraphiQL?

0 Likes