Guides
This guide covers a code-based approach for migrating data to Swell, and how to handle some of the quirks and features specific to Shopify. It's intended to accompany our Migrate to Swell guide.
We'll be using the Shopify Admin API to access your store. To obtain credentials, create a custom app from your Shopify admin under Settings > Apps and sales channels > Develop apps. See Shopify's authentication documentation for more information.
You'll need to enable read access for each data type you wish to import. We'll cover Products, Customers, and Orders here; however, you can migrate others on your own. Save once you've configured the Admin API scopes, then install the app and copy the Admin API access token. Note that Shopify only reveals the token once.
Clone our Shopify migration repo and create a .env file with the following values based on the example provided in the repo:
- Once the .env file has been created, install the packages with npm install.
- Run the scripts with npm run customers. Replace customers with products and then orders to run the different scripts.
In order for the scripts to map associated data correctly, run the scripts in order of customers, products, and then orders.
The customer migration script only pulls in the default_address associated with the Shopify customer account, so the script will not bring over any additional addresses tied to a customer's account. Additional addresses can be added to an account after it has been migrated.
Payment information will need to be migrated over separately and linked to the newly created account id. For additional information on payment migration, see our Migrate to Swell guide.
For additional details, see Shopify's API reference for customers.
Due to the limitations of Shopify's API, you cannot migrate over customer passwords. This means that customers will be prompted to reset their passwords when they attempt to log in to their accounts post-migration.
Swell groups similar products together using categories, which are comparable to Shopify's collections. The difference is categories can be nested, but not assigned automatically. Since categories do not align directly with collections, the script does not transfer them over. You can bulk assign categories to products in the Swell dashboard post-migration. Navigate to the Products tab within the Swell dashboard to manage and create categories or assign products to categories.
For additional details, see Shopify's API reference for products.
There are a few limitations with the migration script for products:
- Product images aren't copied by the script. Pictures hosted on Shopify disappear once the Shopify store closes, so upload them to Swell before then, inline with each product as in Moving a catalog without Admin API access.
- Shopify product ids will change to a Swell product id; the shopify_id will be retained as a custom field.
- The product status will be set to active: false by default.
We recommend using our Import feature for uploading product images, where you can batch import product images either through .CSV or .JSON files by referencing the Swell product id.
The order script migrates all historical order data listed on Shopify while retaining the Shopify product ids and customer information within the object data. A new Swell order id will be assigned to each order, and the original order dates will be preserved on the Swell record.
For additional details, see Shopify's API reference for orders.
A merchant moving their own store can copy its catalog without an Admin API token, from the storefront's public JSON. /collections.json lists the collections, and /collections/<handle>/products.json returns a collection's products with their title, handle, body_html, vendor, variants (each with price, compare_at_price and sku) and images (each with its src). Add ?limit=250 for up to 250 products a request, and &page=2 and so on for more.
- Prices: when a variant has a compare_at_price above its price, the compare_at_price is Swell's price, and the price is the sale_price, with sale: true.
- Images: Swell doesn't fetch images by URL. Download each image and send it inline with the product, as images: [{file: {data: {$base64: …}, content_type, filename}}].
- Categories: create a category for each collection, and put products in it with categories: [{parent_id}]. See Create a product in the Backend API.
- Some stores block automated requests to some of these addresses. If /products.json is blocked, a collection's /collections/<handle>/products.json may still answer.
const { swell } = require('swell-node');
const shop = 'https://example-store.com';
const handle = 'headphones';
// The collection becomes a category
const category = await swell.post('/categories', { name: 'Headphones', slug: handle, active: true });
const res = await fetch(`${shop}/collections/${handle}/products.json?limit=250`);
const { products } = await res.json();
for (const p of products) {
const v = p.variants[0];
const onSale = v.compare_at_price && Number(v.compare_at_price) > Number(v.price);
const images = [];
for (const img of p.images) {
const file = await fetch(img.src);
images.push({
file: {
data: { $base64: Buffer.from(await file.arrayBuffer()).toString('base64') },
content_type: file.headers.get('content-type'),
filename: new URL(img.src).pathname.split('/').pop(),
},
});
}
await swell.post('/products', {
name: p.title,
slug: p.handle,
description: p.body_html,
sku: v.sku,
price: onSale ? Number(v.compare_at_price) : Number(v.price),
...(onSale && { sale: true, sale_price: Number(v.price) }),
images,
categories: [{ parent_id: category.id }],
active: true,
});
}This covers each product's main details. For customers, orders and full product data, use the Admin API scripts above.
That's it—congrats on getting your store migrated to Swell! If there are still additional data sets you are wanting to migrate, see our general migration guide for more information on migration for data not covered within this guide. Otherwise, you're all set. Thank you for choosing Swell.