d
Topic
Posts:
22
Last edited 13 days ago

ShopifyQL vs GraphQL

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?

i
Replies
Zameer Masjedee Shopify Employee
Posts:
89
Last edited 12 days ago

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.

Posts:
22
Last edited 12 days ago

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?

Posts:
501
12 days ago

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
Posts:
22
12 days ago

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?

Zameer Masjedee Shopify Employee
Posts:
89
12 days ago
g
2
upvotes

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.

Posts:
501
12 days ago
g
1
upvotes

Ooooh... how sweet is that!

Zameer Masjedee you just made my day. Thanks!

I turn coffee in to code - since 1998
Posts:
22
Last edited 12 days ago

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?

Zameer Masjedee Shopify Employee
Posts:
89
12 days ago

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. 

Posts:
22
12 days ago

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?

Zameer Masjedee Shopify Employee
Posts:
89
12 days ago

We currently have a set of Developer Tools that are unfortunately macOS only, but you can access them here

It's able to generate random Products, Customers and Orders, and should be useful for testing GraphQL queries.

There are also a few apps on our App Store that you can download onto your shop to generate additional sample data for you.

Posts:
22
12 days ago

Is there any documentation that says what can be generated? For example, can discount codes be generated for orders?

Where is the test data stored?

Zameer Masjedee Shopify Employee
Posts:
89
12 days ago

Hey David,

The exact functions available are not currently documented. But the tool lets you search products, generate data and build Polaris layouts. I would recommend downloading it to try it out, it's very easy to use.

The tool links to a development shop, which is where all the generated data is kept.

Posts:
22
12 days ago

Can it generate and use discount codes for orders?

Posts:
22
Last edited 12 days ago

I created products, customers and orders with the tool. I also created discount codes but it doesn't look like any of the generated orders used them. How do I apply a discount code to an order or create a new order with a discount code?

Zameer Masjedee Shopify Employee
Posts:
89
Last edited 12 days ago

Hey David,

Discount Codes isn't functionality built into the Developer Tools just yet.

What I would recommend doing, is using the API to create your own dummy orders with discount codes now that you have a catalogue of Products and Customers generated for you.

Using a few loops, you should be able to create a large number of orders, where you set the discount codes yourself.

Have a look at our Order API documentation for more info on this.

Posts:
22
Last edited 12 days ago

How do I create and execute a POST command with the API? Can the tool be used for this? If I want to create order o1 for product p1 and customer c1 using discount code dc1, are there any examples that would help me to create something appropriate. Do I need to create JSON to do this?

Zameer Masjedee Shopify Employee
Posts:
89
12 days ago
g
1
upvotes

Hey David,

This forum is intended to assist with Shopify specific API questions. If you're currently in the process of learning how to make HTTP requests to an API, I would recommend searching out some online resources that can walk you through it.

Stackoverflow is often a great resource for questions like these!

Posts:
22
11 days ago

I am trying to get clarification of your comments

What I would recommend doing, is using the API to create your own dummy orders with discount codes now that you have a catalogue of Products and Customers generated for you.

Using a few loops, you should be able to create a large number of orders, where you set the discount codes yourself.

 as I don't know how and where to use the API to create orders. Can you either explain how to do this or point me somewhere? Where do I create and execute a POST action? Can the developer tool be used for this?

Posts:
22
Last edited 11 days ago

I created 40 orders with the developer tool and I can see them in my dashboard. When I enter

GET /admin/orders.json

with the tool I get the response

data: {} 1 key

  orders: [] 0 items

When I enter

GET /admin/storefront_access_tokens.json

I get

data: {} 1 key

  errors: "App must be extendable to create a storefront access token."

BTW, is there any way to exit the developer tool other than by using kill -9?