How to load data from Shopify to MS SQL Server

Blendo Team

This post helps you with loading your data from Shopify to MS SQL Server. If you are looking to get analytics-ready data without the manual hassle you can integrate Shopify to MS SQL Server with Blendo, so you can focus on what matters, getting value out of your orders’ data.

Extract your Shopify’s data

Shopify exposes its complete platform to developers through their API. It is used by thousands of developers to create applications that are then sold through the Shopify marketplace.

As a Web API following the RESTful architecture principles, it can be accessed through HTTP. As a RESTful API, interacting with it can be achieved by using tools like CURL or Postman or by using HTTP clients for your favorite language or framework. A few suggestions:

  • Apache HttpClient for Java
  • Spray-client for Scala
  • Hyper for Rust
  • Ruby rest-client
  • Python http-client

Shopify also offers a number of SDKs that are officially supported and maintained by them and that can be used to access their platform for different uses. For example, by using the iOS and Android Buy SDK it is possible to add Shopify checkout capabilities to your mobile application. Other SDKs that are offered are:

You will need more time to read this post than integrating Shopify to MS SQL Server.

Effortlessly Sync All Your Shopify Data to MS SQL Server

Shopify API Authentication

There are two different types of applications in Shopify when it comes to authenticationprivate and public apps.

Private apps will only function on individual stores, so you don’t need to authenticate them through Oauth. You can get Private app credentials through your Partner dashboard or by logging into any Shopify admin. You can also use this API key to manipulate your store using the API console, without the need for building a fully functional app.

The apps you create in your Partners dashboard function as public apps which can be made available for download in Shopify’s App Store if you meet the criteria.

Shopify rate limiting

The API call limit operates using a “leaky bucket” algorithm as a controller. This allows for infrequent bursts of calls and allows your app to continue to make an unlimited amount of calls over time. The bucket size is 40 calls (which cannot be exceeded at any given time), with a “leak rate” of 2 calls per second that continually empties the bucket. If your app averages 2 calls per second, it will never trip a 429 error (“bucket overflow”).

Endpoints and available resources

Shopify exposes 35+ endpoints covering all the possible touch points of e-commerce. Some of the most important resources that can be accessed through these endpoints are the following:

  • Abandoned checkouts: used to return abandoned checkouts. A checkout is considered abandoned when a customer has entered their billing & shipping info but has yet to complete the purchase.
  • ApplicationCharge: Request to charge a shop a one-time fee by issuing this call.
  • Article: Operations concerning articles in your Blog.
  • Asset: files that make up the theme of a shop.
  • Blog: Shopify, in addition to the e-commerce features also offer an environment where the merchant can create a Blog for her shop.
  • CarrierService: A Carrier Service (also known as a Carrier Calculated Service or Shipping Service) provides real-time shipping rates to Shopify.
  • Collect: An object that connects a product to a custom collection.
  • Customer: A customer resource instance represents a customer account with the shop.
  • Event: Events are generated by specific Shopify resources when specific things happen, such as the creation of an article.
  • Order: An order is a customer’s completed request to purchase one or more products from a shop.
  • Product: A product is an individual item for sale in a Shopify shop.
  • Transaction: Transactions are created for every order that results in an exchange of money.

For a complete list of endpoints, you can see here.

It is clear that with such a rich platform and API the data that can be pulled out of Shopify are both valuable and come in large quantities. So, let’s assume that we want to pull all events out of Shopify to use them for further analysis. To do so we need to make a request to the Event endpoint like this.

GET /admin/events.json?filter=Product,Order

This request will get us back all the events that are related to Products and Orders for our shop. The response will be in JSON and will look like the this:

HTTP/1.1 200 OK
{
  "events": [
    {
      "id": 677313116,
      "subject_id": 921728736,
      "created_at": "2008-01-10T08:00:00-05:00",
      "subject_type": "Product",
      "verb": "create",
      "arguments": [
        "IPod Touch 8GB"
      ],
      "body": null,
      "message": "created a new product: <a href=\"\/admin\/products\/921728736\">IPod Touch 8GB<\/a>.",
      "author": "Shopify",
      "description": "created a new product: IPod Touch 8GB.",
      "path": "\/admin\/products\/921728736"
    },
    {
      "id": 365755215,
      "subject_id": 632910392,
      "created_at": "2008-01-10T07:00:00-05:00",
      "subject_type": "Product",
      "verb": "create",
      "arguments": [
        "IPod Nano - 8GB"
      ],
      "body": null,
      "message": "created a new product: <a href=\"\/admin\/products\/632910392\">IPod Nano - 8GB<\/a>.",
      "author": "Shopify",
      "description": "created a new product: IPod Nano - 8GB.",
      "path": "\/admin\/products\/632910392"
    }
  ]
}

Inside the response, there will be an array of objects with each one representing one Order or Product.

Events are generated for the following resources:

  • Articles
  • Blogs
  • Custom Collections
  • Comments
  • Orders
  • Pages
  • Products
  • Smart Collections

By using the “limit” and “page” parameters it is possible to page your results in case that you need to pull out a large number of events. Additionally, there are a number of ways that you can filter the results for example based on a date, so in a continuous data extraction process, it is possible to pull only new data and avoid duplicates. This can be achieved by using the “created_at_min” and “created_at_max” parameters in your GET request.

After you have successfully pulled your data by a Shopify API you are ready to extract and prepare them for MS SQL Server. Of course, the above process is only for one of the available resources, if you would like to have a complete view of all the available data then you will have to create a much complex ETL process including the majority of the 35+ resources that Shopify has.

About Shopify

Shopify is one of the easiest and simple to use managed e-commerce platforms. It offers an easy way for anyone to create an online store and start selling goods. It natively integrates with services like Stripe and Paypal to make things even easier for potential users of the platform. Shopify also offers a very rich app marketplace, where its users can find powerful extensions and plugins that can enhance their online shops. They have a quite flexible pricing model that can cover the needs of very small to large online shops, you can start with the lite version and as your business grows quite easily you can jump to a larger plan. Some of the benefits of Shopify are:

  • Easy to start. Both the experience the platform offers and the pricing model makes it extremely easy for anyone to set up and run an online shop.

  • No technical skills required. As a self-managed SaaS product, Shopify requires minimum technical skills from its users.

  • It is hosted. Which means that you don’t have to care about where to host your online shop, they offer all the infrastructure and services needed without requiring you to delve into technical details.

  • It can be personalized. Although a hosted platform, it can be easily customized to meet your brand.

Additionally, Shopify has succeeded in creating a unique ecosystem of developers who build added value services and extensions on their platform. A large number of plug-ins are available that help users of Shopify to personalize even more their e-shops while developers can generate a good income by selling their applications and extensions. Of course, such a success was built on top a well-designed API that exposes the whole platform to the developers. This API will be also used in this article to show how we can pull out valuable data.

Shopify Data Preparation for Microsoft SQL Server

As in every relational database, SQL Server requires a well defined database schema before we start populating with data. Data is organized in schemas, which are distinct namespaces where database objects belong to.

The most common database objects are of course tables which have a number of columns with each one having a declared data type. MS SQL Server supports a large number of different data types. Which give us great flexibility in expressing the data that we have and at the same time optimizing our data warehouse.

When working with data coming from web services, where data is usually serialized in JSON, it is important to correctly map the data to the right data types. As changing the data types in the future is a process that might cost in downtime of your database, it is important to spend enough time thinking about the proper data type assignments.

For example, dates in JSON are just strings, but when storing date objects in a database, we can enhance analytics with great capabilities by transforming the raw string data into an appropriate date type. A typical strategy for loading data using Shopify to MS SQL Server database is to create a schema where you will map each API endpoint to a table. Each key inside the Shopify API endpoint response should be mapped to a column of that table and you should ensure the right conversion to an SQL Server compatible data type.

Of course, you will need to ensure that as the data types from the Shopify API might change, you will adapt your database tables accordingly, there’s no such thing as automatic data type casting. After you have a complete and well-defined data model or schema for Microsoft SQL Server, you can move forward and start loading your data into the database.

About Microsoft SQL Server

Microsoft SQL Server is one of the oldest and most mature database systems. Its first version was introduced about 28 years ago, in 1989 and Microsoft has been consistently supporting and extending the product until today.
So, it’s no surprise that Microsoft SQL Server has one of the richest feature sets among the currently available database systems.

SQL Server is delivered in different editions or flavors. With the most notable being the Enterprise edition which can manage databases as large as 524 petabytes utilizing up to 12 terabytes of memory and 640 CPU processors. A free and scaled down version which is called Express.

A Business Intelligence version focusing on use cases where BI is performed on premises. This version is actually a bundle of different products, including the core database system, together with other Microsoft related products that can be used for BI purposes like visualization and data management.

In addition, there are also plenty of specialized versions of the database like the Compact edition that can be used on small devices and of course the Azure version, which is the cloud-based edition of SQL Server. Microsoft SQL Server incorporates a modular architecture that can extend the database with additional services. Replication services can extend the database to a cluster version and thus help with scaling and fault tolerance.

The SQL Server Analysis Services, augment the database with with OLAP and data mining capabilities, making the database ideal for the workloads that we care about in this guide.

Load data from Shopify to MS SQL Server

As a feature-rich and mature product, MS SQL Server offers a large and diverse set of methods for loading data into a database. One way of importing data into your database is by using the SQL Server Import and export Wizard. With it and through a visual interface you will be able to bulk load data using a number of data sources that are supported.

You can import data by another SQL Server, from an Oracle database, from Flat Files, from an Access Data Source, PostgreSQL, MySQL and finally Azure Blob Storage. Especially if you are using a managed version of MS SQL Server on Azure, you should definitely consider utilizing the Azure Blob Storage connection.

In this way, you will be loading data as Blobs on Azure and your MS SQL  Server database will sync with it through the Import and Export Wizard.

Another way for importing bulk data into an SQL Server, both on Azure and on premises, is by using the bcp utility. This is a command line tool that is built specifically for bulk loading and unloading of data into an MS SQL database.

Finally and for compatibility reasons, especially if you are managing databases from different vendors, you can you BULK INSERT SQL statements.

In a similar way and as it happens with the rest of the databases, you can also use the standard INSERT statements, where you will be adding data row-by-row directly to a table. It is the most basic and straightforward way of adding data into a table but it doesn’t scale very well with larger datasets.

So for bulk datasets, you better consider one of the previous methods.

Updating your Shopify data on MS SQL Server

As you will be generating more data on Shopify, you will need to update your older data on an MS SQL Server database. This includes new records together with updates to older records that for any reason have been updated on Shopify.

You will need to periodically check Shopify for new data and repeat the process that has been described previously while updating your currently available data if needed. Updating an already existing row on a SQL Server table is achieved by creating UPDATE statements.
Another issue that you need to take care of is the identification and removal of any duplicate records on your database. Either because Shopify does not have a mechanism to identify new and updated records or because of errors on your data pipelines, duplicate records might be introduced to your database.

In general, ensuring the quality of the data that is inserted in your database is a big and difficult issue and MS SQL Server features like TRANSACTIONS can help tremendously, although they do not solve the problem in the general case.

The best way to load data from Shopify to MS SQL Server

So far we just scraped the surface of what you can do with MS SQL Server and how to load data into it. Things can get even more complicated if you want to integrate data coming from different sources.

Are you striving to achieve results right now?

Instead of writing, hosting and maintaining a flexible data infrastructure use Blendo that can handle everything automatically for you.

Blendo with one click integrates with sources or services, creates analytics-ready data and syncs your Shopify to MS SQL Server right away.

Take ownership of the insights that live in Shopify to transform your e-commerce business.

Blendo is the easiest way to automate powerful data integrations.

Try Blendo free for 14 days. No credit card required.