How do I import metafields from a CSV file?

Modified on Sat, 29 Jul 2023 at 10:45 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 will also do the trick. Please note that there is a limit on the maximum size of a CSV file you can upload, which depends on your subscription plan: 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), and see the list of requirements dictated by Shopify's API (4):


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). In order to create a metafield, one has to make a proper API request. And 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 product 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 literally 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 resource identifier (1) and change the format of a CSV file (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

Skip empty metafields

If you select this option, metafields that do not have value (empty "value" column) in your CSV file will have no effect on your existing data, even if a metafield with the same namespace/key combination already exists.


Delete empty metafields

If you select this option, all existing metafields that have empty values in your CSV file will be deleted from your Shopify store. 



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