How do I import metafields from a CSV file?

Modified on Sat, 11 May 2024 at 08:22 PM

TABLE OF CONTENTS

Intro

In this tutorial, you will learn about data imports, their real-world applications, supported file formats, and additional options. 

The most common use cases include, but are not limited to:

1) copying data from another Shopify store;

2) importing data from a spreadsheet into metafields;

3) deleting metafields


Accessing the data import menu


Go to the Apps section of your Shopify admin panel (1) and select our app from the list of installed apps (2):


Next, navigate to the Bulk Actions tab of our menu (3) and go to Import (4):


Configuring a data import

Uploading a CSV file

CSV stands for comma-separated values, the file format chosen by Shopify to handle data imports/exports. This format expects the data to be presented by rows of columns separated by a comma (“,”).

You can upload a file from your PC/laptop by pressing this button:

The drag-and-drop method is also supported. 

File size limits

Depending on your subscription plan, there is a limit on the maximum size of a CSV file you can upload: up to 50 Mb for Rookie and Adept, up to 250 Mb for Guru, and up to 500 for Guru Plus. 


On this page, you can also change the resource type (1), set a delimiter for your CSV file (2, optional), download a sample file (3), see the list of requirements dictated by Shopify's API (4), and move to the mapping step (5):


Understanding the requirements

Just like any other type of data, metafields are stored in Shopify's database and are securely manipulated via the API (either GraphQL or REST). To create a metafield, one has to make a proper API request. To make such a request, one has to fill in the following attributes:

1) resource identifier;
2) metafield type;
3) metafield namespace;
4) metafield key;
5) metafield value;

The “resource identifier” must be a valid ID, and the ID is always unique. Luckily, our app is smart enough to map secondary resource identifiers to system IDs: the handle for products, the SKU for products and variants, emails for customers, etc.

Namespace is used to group different metafields (something like a folder or a logical container); the key is a unique identifier to reference the information stored in metafields; value contains the data itself; and type represents the data type for a specific metafield: string, number, reference, etc. It's impossible to create metafield without even one of these attributes.


Data mapping

Based on the information we discovered earlier, there must be a matching column for each of these attributes in your CSV file. Thanks to the data mapping step, you can match them to ensure that the data is imported correctly. Once a CSV file is uploaded, the mapping section will show up. During this step, you can map the columns from your file to match metafield attributes. For instance, mapping a column that contains the resource ID would look like this:


Here you can also change the file format (1) and resource identifier (2):

When you are done configuring the import task, review the settings and launch the import.


Supported formats

Some merchants prefer to manage spreadsheets via editors like Excel, Numbers, or Google Sheets, while others might tend to automate the process with custom tools. Hence, our app supports two different layouts of CSV files:
1) human-friendly "columns";
2) automation-focused "rows" that allow for better data integrity.
The main difference is that when metafields are exported as "columns", each resource (product, collection, etc.) is represented by a single row with separate columns for each metafield, whereas, when exported as "rows" - each metafield is represented by an individual row that contains both the metafield and the parent resource data.


Here you can see the difference the format makes for 30 metafield records:

1) The rows format

2) The columns format

Additional options

Empty metafields

By default, metafields that have no value in your CSV file will not affect existing data. If you want to replace the existing values with empty strings, you must switch the toggle to Delete. Due to the peculiarities of Shopify, it's technically impossible to create a metafield with empty values, meaning you can only remove those metafields.


Duplicated images (for file_reference metafields only)

By default, our app avoids replacing existing images when uploading the data from your file. This means that if there's an image named "image1.jpg" in your file and a file with the given name already exists in your Shopify store, our app will generate a new unique name for that file. However, you can also replace the existing "image1.jpg" image with the one from your file by switching the toggle to Replace.



Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article