Getting Started with the Shopify API

This post is extracted from my free email course, “Mastering Shopify Apps”. Sign up to the course to receive more content like this in your inbox every week.

Even if you’ve never worked with a HTTP API before, or aren’t particularly technical, it’s actually quite easy to get started working with the Shopify API.

Let’s get our hands dirrty and see how to use the Shopify API to retrieve information from our store.

The Shopify API

In tech-speak, Shopify’s API is REST-based, uses JSON, and is delivered over In tech-speak, Shopify’s API is REST-based, uses JSON, and is delivered over HTTP(S). If that didn’t make sense to you, don’t worry! Here are those buzzwords broken down in plain language:

  • REST-based simply means that the API is organised around the idea of resources, which are fetched and updated through a set of actions. In our case, the resources we’re dealing with are Shopify objects like products, collections, orders and content pages, while the actions we’re performing on them are things like reading, updating, creating and deleting them.

    REST purists are probably jumping up and down at the above description, but it’s honestly not something you need to worry about too much to actually work with the API. If you’re super interested, you can read more about REST.

  • JSON is probably familiar to you. It’s a simple, easy to use data format for transferring information that has the advantage of being quite human readable. Because it’s so common, all programming languages have libaries to help you work with JSON data.

    We’ll see an example of what JSON looks like in a second.

  • HTTP(S) means that data is sent between your program (a client) and the API (the server) using the HTTP protocol - the same method your browser uses to fetch websites. The (s) at the end there indicates that all requests made to the Shopify API must be made with SSL encryption (eg, https://).

    Again, the ubiquity of HTTP(S) means that pretty much every programming language is able to interact with the Shopify API - you don’t need to have a particular code library available for your language of choice.

Start playing with the API with a single click

Okay, that’s enough academia for this lesson. Want to make your first Shopify API call? Just click this link:

https://797ed43b5c0c93141a5e6a2c365c37f7:4b1b805b05f3788dd604003c0db2471c@mastering-apps.myshopify.com/admin/products.json

Nice work! Because the Shopify API is HTTP-based, and internet browsers all speak HTTP, we can make this first API request directly from within the browser.

If all goes well, you should receive something that looks like this in your browser window:

{"products":[{"id":1795476932,"title":"Candle","body_html":"\u003cmeta charset=\
"utf-8\"\u003e\u003cspan\u003eDonec id viverra tellus. Ut eget suscipit enim. Do
nec pharetra magna dolor, et egestas quam elementum quis.\u003c\/span\u003e","ve
ndor":"Screencast","product_type":"Candle","created_at":"2015-10-14T06:06:08-04:
00","handle":"candle","updated_at":"2015-10-14T06:06:08-04:00","published_at":"2
015-10-14T06:06:01-04:00","template_suffix":null,"published_scope":"global",....

If you hadn’t guessed it already, that’s a list of all of the products in our store in JSON format.

Breaking down the API URL structure

Let’s break down the different components of the URL we just used to interact with the API.

https://**797...7f7:4b1...71c@mastering-apps.myshopify.com/admin/products.json
    ↑ Using HTTP with SSL
    
    
https://797...7f7:4b1...71c@mastering-apps.myshopify.com/admin/products.json
                 ↑ Authentication information
                 
                 
https://797...7f7:4b1...71c@mastering-apps.myshopify.com/admin/products.json
                         Our store URL ↑
                         
                         
https://797...7f7:4b1...71c@mastering-apps.myshopify.com/admin/products.json
                                                Resource path ↑


https://797...7f7:4b1...71c@mastering-apps.myshopify.com/admin/products.json
                                                            JSON format ↑

If you haven’t already, you can play around with the URL requested to retrieve different resources, or to retrieve resources in a different way. For example:

  • Retrieve a list of content pages, rather than products, by fetching /admin/pages.json;
  • Restrict the information fetched by the request by adding a fields query parameter to specify the fields you’re interested in: /admin/products.json?fields=id,title
  • Return resources in a paginated fashion by adding limit and page query parameters: /admin/projects.json?limit=2&page=2

The Shopify API Documentation provides a great breakdown of what resources are available, and how you can alter the URL and query parameters to retrieve different resources.

Using the API on your own store

The URL above fetches information from our demo store, mastering-apps.myshopify.com. What if we want to inspect information from our own store using the API?

We can’t just edit the mastering-apps section of the URL above, because the authentication information in that URL is only valid for the demo store.

There are two types of authentication you can use to connect to a Shopify store via the API:

  1. Via a Username and password (used by Private Apps);
  2. Via an OAuth Token (used by Public Apps).

The authentication method we used above utilises the Private App approach, so that’s what we’ll use to connect to our own store. We’ll tackle the OAuth authentication approach in a later lesson.

The username and password used for authentication is contained in the 797...7f7:4b1...71c section of the URLs in our example above, between the https:// and @mastering-apps... parts of the URL. The first series of characters before the : colon is our API Key (username), and the series of characters following that are the password.

To generate a username and password for your own store, follow the instructions here on creating a Private App. Once the app is created, you’ll have your own API Key and password you can slot into the appropriate location in the URLs above to fetch information from your own store. Don’t forget to update the domain of the shop in the URL from mastering-apps.myshopify.com to that of your own store!

https://API_KEY:PASSWORD@your-store.myshopify.com/admin/products.json

Next steps

That’s it for this post - if you’ve never tried it before, I definitely encourage you to play around with the API on your own store to get a feel for the different resources that are available and making requests through your browser.

If you’re interested in learning more about the Shopify API and how to use it to build applications and solve problems, please sign up for my free email course Mastering Shopify Apps.