Turn a Shopify backend open-source and headless in less than 10 minutes
Tags: javascript, webdev, node, opensource
Published: 2022-01-16 15:15:20

In this article, I will show you how to migrate *all* of your products and collections from a Shopify backend to an open-source headless commerce backend, [Medusa](https://github.com/medusajs/medusa), in less than 10 minutes.

Medusa is an open-source Shopify alternative giving you all of the necessary primitives to build and operate a webshop. Below, I will first walk you through the features of Medusa. Then I’ll move on to a guide on how to use the plugin to quickly import your Shopify products and collections into Medusa. Finally, I’ll go into a bit more depth on some of the reasons why you should consider moving from Shopify to an open-source headless platform.

## Why Use Medusa

As [Medusa](https://www.medusajs.com/) is an open-source headless commerce platform, it allows you to completely customize and compose your stack to fit your needs. You’re not bound to a monolithic architecture where everything is tightly coupled. Some of the main benefits of this are:


1. It gives you full flexibility to build any type of frontend(s) you may prefer - Medusa has starters in [Next.js](https://github.com/medusajs/nextjs-starter-medusa) or [Gatsby](https://github.com/medusajs/gatsby-starter-medusa) to set up a high-performing storefront out-of-the-box so you have a good starting point before starting to customize it to your needs. You can check out a demo of the starer [here](https://start.medusajs.com/). 
2. The open-source nature lets you customize the core engine to cater to more advanced business cases and requirements that are often outside the scope of monolithic platforms. The code-base is meant to be extendible and customizable which you can feel from the very first time you try to add own functionality to it.
3. Medusa's plugin architecture makes it intuitive and easy to manage your integrations, switch providers and grow with ease. It even comes with a lot of pre-made integrations to CMSs, payments, shipping, analytics, marketing and more. You can check them all out [here](https://github.com/medusajs/medusa/tree/master/packages).
4. Also on features, Medusa provides a few different additions that makes it stand out such as the option to define regional currency, shipping and payment options which is one of the more known issues for business owners running on Shopify and wants to sell across markets. Another example is return, exchange and claim handling which are all fully-automated processes in Medusa that makes it easy to use for customer service personnel.

There are therefore many reasons to migrate from a monolithic solution like Shopify to a headless open source solution. In the next session, we will walk through how easy this type of migration process can be.


## How to Migrate Data from Shopify to Medusa

In this section of the article, you’ll learn how to use Medusa’s plugin to import your products and collections from Shopify into Medusa.

This section assumes you already have a Shopify store up and running with products to import. It also assumes you already have Medusa set up and ready to use. If you don’t, then you should check out [this tutorial on how you can set up and run Medusa](https://dev.to/medusajs/get-started-with-medusa-the-open-source-alternative-to-shopify-305j).

In my case, I have 30 products in my Shopify store, each having many variants and attributes.


![Shopify Products](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/300bdvqcbijncqiey56z.png)

![Shopify Product](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yqbkrpjqik5jzbz9shi3.png)



### Create a Private Shopify App

To be able to import the data from Shopify into Medusa, you need to create an App in your store with limited permissions. This will give you different types of keys to access the App and the data in the store.

Open your store’s dashboard. Then, choose *Apps* from the sidebar. Then, scroll down and click on *Manage private apps*.

![Manage Private Apps Link](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0jlrvewzvqalgmizuio0.png)


If you haven’t enabled private apps previously, you’ll be asked to enable them first. click on *Enable private app development* to enable it.

After you have enable private app development, you’ll be able to create a private app. Click on *Create private app* to get started.


![Create Private App](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dcvh7ttgilvxnhadhzoh.png)

You’ll then need to enter your app’s name and your email. Then, scroll down to the Admin API section and click on *Show inactive Admin API permissions*. Scroll down to Products and choose Read Access from the dropdown. Medusa only needs to read products and collections.

![Products Permissions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4hcjlolm3xwrj1ghkfn3.png)

Scroll down to the end of the page and click the *Save* button. Then, click *Create App* in the pop-up that shows up.

After you create the app, you’ll be able to see a set of keys such as API Key and Password. What you’ll need for the plugin is the password, so keep it available for the next step.


### Add medusa-source-shopify to your Medusa store

You’ll now integrate the [Shopify plugin](https://github.com/medusajs/medusa/tree/ec0f2df2854d497f49ce94f74636723f0c0e2e26/packages/medusa-source-shopify) into your Medusa server. To integrate the plugin, you need the following:


1. The Shopify domain name and the password of the Shopify app you want to link to.
2. PostgreSQL database used with your Medusa server.

At this point of the article, it’s assumed you have all of these requirements ready.

Open your terminal in your Medusa server installation and run the following command to install the plugin:

```bash
    npm i medusa-source-shopify
```

Then, in `.env` add the following new variables:

```
    SHOPIFY_DOMAIN=
    SHOPIFY_PASSWORD=
```

Where `SHOPIFY_DOMAIN` is the subdomain name of your Shopify store (for example, my store is shahednasser.myshopify.com, so the value would be shahednasser), and `SHOPIFY_PASSWORD` is the password generated when you created the app earlier.

Then, open `medusa-config.js` and add a new entry into the `plugins` array:

```js
    const plugins = [
      ...,
      {
        resolve: 'medusa-source-shopify',
        options: {
          domain: process.env.SHOPIFY_DOMAIN,
          password: process.env.SHOPIFY_PASSWORD
        }
      }
    ];
```

This will add the Shopify plugin into your Medusa server and will pass the options for the domain and password from the environment variables you just added.

And that’s all you need to integrate Medusa with Shopify to import your data. All you need to do now is run your server:

```bash
npm start
```

And the server will import all the products and collections from Shopify into your Medusa store. Your server will do that everytime you start it, so your products and collections will be automatically synced on server restart.

Your products and collections will be imported with pricing, variants, and all the attributes and details you had in your Shopify store.

![Products in Medusa](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e5m1t857zaur5t8s389d.png)

## Why Migrate From Shopify to an Open Source backend

According to [BuiltWith](https://trends.builtwith.com/shop/Shopify), there are over 3.7M live websites that use Shopify at the time of writing this. This makes Shopify one of the most used ecommerce platforms. Shopify is known to provide an easy experience for brands and businesses of any size to launch and operate their online business.

Although Shopify has a lot of advantages that make businesses and developers gravitate towards it, it all comes at the expense of *less ownership of the tech stack*. At first glance, especially for smaller businesses that are just looking to start a store as soon as possible, it may seem like an irrelevant detail.

However, any business that have expanded from a few sales a week to becoming a serious ecommerce business can tell how important it is to be able to fully own the tech stack behind your webshop. Owning your website’s codebase, and having the flexibility to change and reform it based on your growing business needs is an important detail that will come up as time passes by. Shifting integrations, opening up new markets, customizing the UX are just some of the areas in which developers encounter problems when scaling with a monolithic platforms.

In addition to the issues related to scaling, using an open-source solution means that the platform you’re using is free forever. Using Shopify comes at a high price that grows as you scale as it is  often directly linked to your webshop revenue and transaction volume. This will add to the additional costs of creating and operating your system.


## Conclusion

Shopify is a powerful ecommerce platform that is used by millions of websites across the globe. Although it has a ton of great features, it has some disadvantages as well, most notably your tech stack ownership.

With ecommerce platforms like Medusa you can completely own your tech stack and have many of the features you like about Shopify into your own open-source store. Medusa even makes it easier by allowing you to import your data from Shopify into Medusa using this easy-to-use plugin.

Should you have any issues or questions related to Medusa, then feel free to reach out to the Medusa team via [Discord](https://discord.gg/F87eGuwkTp).