Working with the Shopify API: Developer Guide

By Mark Geene in GET/technical Posted Oct 11, 2016

Thousands of small businesses around the world see the Shopify API as the most direct route to running their own professional e-commerce store. It's fairly easy to integrate into an existing company website, so Shopify can handle all the heavy database work of running an online store. The other main benefit is a that there are many well-designed themes for a slick, pre-packaged UI. Think of it as the Wordpress of online shops.For developers, Shopify integrations are straightforward. It's implemented as JSON over HTTP and there is a URL for each resource (Order, Product, Collection, etc.). Shopify's developers built the service as REST APIs, following as the REST principles as closely as the could.

To get started with the Shopify API you have to register to become a Partner. All API messaging goes through Shopify applications that you will create. The API will communicate with the REST web service using ActiveResource, which can only be configured once you have an authorized URL for a Shopify storefront.

Best Practices and Tips

Start by setting up a Usage Plan for your e-commerce APIs. This should cover info like how many items will be in the database, how often inventory will be updated and how often you want to run fulfillment processes, etc. This step is critical to laying out your workflow because every update requires an API call. A /get function for an e-commerce store with 1000 items will require just four API calls of 250 items each, but updating everything in the inventory will take 1000 API calls.

Even if you are sending concurrent requests, that can take up too many resources. Update the absolute minimum. Here's an example from GitHub on how to just update changes to ID numbers and amounts:

def update_inventory(id, vid_quantities)
variants = do |vid, qty|
{ "id" => vid, "inventory_quantity" => qty }
data = {
"product" => {
"variants" => variants
request(:put, "products/#{id}.json", body: data.to_json)
update_inventory(1234567, {2222222 => 100, 3333333 => 200})


Shopify pointed out that reprocessing the same image URLs was one of their biggest resource drains.

More Tips for Developers

original-shopify.jpgThe OnAuth verification code on this is still a bit vague, so you may need to check the message boards for workarounds if you are having HMAC verification issue. You'll see that HMAC verification procedures are not the same as what you have to do to verify webhooks. HMAC verification for webhooks is covered in Shopify's Using Webhooks tutorial.

Another point to consider is that some developers run into errors when they try to process large blocks of orders. For questions around issues like these, StackOverflow's Shopify discussion threads offer some good tips and original ideas.

The Bottom Line

The growing need for ecommerce integrations with Shopify APIs can offer developers can open you up to a reliable source of revenue. Atlee Clark, Shopify's director of apps and developer relations, outlined the market this way: “We offer recurring revenue (an 80/20 rev share) and exposure to our more than 275,000 merchants. In 2015 alone, app developers made $11M through the Shopify platform."

Clark pointed out that Hextom is the perfect example. Two developers in Toronto started out putting together Shopify API integrations in a coffee shop. They built nine apps in six months, resulting in 25,000 installs and thousands of dollars in monthly revenue. If you run into a snag with the API integrations, there are active communities at the at the Shopify website and boards like StackOverflow to help you work out the bugs.

Access Podcast