# How to import categories

## Before importing

A prerequisite to importing [categories](https://docs.struct.com/fundamental-concepts/data-model) is having an excel spreadsheet with the data organized in named columns. For this tutorial we have a made a simple spreadsheet containing information about a clothing [category](https://docs.struct.com/fundamental-concepts/data-model) tree.

<figure><img src="https://2141378775-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUonpFWM7AJ0xVVXV1tr%2Fuploads%2Fgdruns62QfSPhjGQYPeT%2Fimage.png?alt=media&#x26;token=1b1ee144-7f09-4700-bed9-5f3844b157ae" alt=""><figcaption><p>Excel spreadsheet with headers and data</p></figcaption></figure>

In addition, if you want to import a tree structure, you need to give the system a way of identifying parent [categories](https://docs.struct.com/fundamental-concepts/data-model) when importing. One way of doing this is adding an [identifier](https://docs.struct.com/tutorials/guides/how-to-use-import/broken-reference) to the [catalogue](https://docs.struct.com/fundamental-concepts/data-model) you are importing the [category](https://docs.struct.com/fundamental-concepts/data-model) tree under.

<figure><img src="https://2141378775-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUonpFWM7AJ0xVVXV1tr%2Fuploads%2F6dPYhWuZ4lPMatMsfyA2%2Fimage.png?alt=media&#x26;token=e4cb359c-9877-43ae-bc88-19ddf7e5b8a1" alt=""><figcaption><p>Identifier on catalogue</p></figcaption></figure>

In this example we have created an identifier called 'ClothingCategoryId' with pattern '{0}' using the property 'CategoryAlias'. In short this means the identifier will have the same value as 'CategoryAlias'.

{% hint style="info" %}
Read more about creating identifiers on catalogues here: [Identifier details](https://docs.struct.com/tutorials/guides/how-to-use-import/broken-reference)
{% endhint %}

## Starting the import

To start importing you choose the excel spreadsheet with the data you want to import, in this tutorial the spreadsheet is called "CategoryImportFile.xlsx".

Next you need to choose the correct Import type. When importing [categories](https://docs.struct.com/fundamental-concepts/data-model), [products, variants](https://docs.struct.com/fundamental-concepts/data-management), variant groups or [global lists](https://docs.struct.com/tutorials/guides/how-to-use-import/broken-reference) the 'General Excel Import' type is used.

While it is possible to include media assets when importing, this will not be covered in this guide. For this reason we leave 'Upload assets' untoggled.

<figure><img src="https://2141378775-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUonpFWM7AJ0xVVXV1tr%2Fuploads%2FByiSk8qdV92YKTeTjH7j%2Fimage.png?alt=media&#x26;token=aeafa1cb-7355-41ca-bd6f-986dfb162cef" alt=""><figcaption><p>Import page</p></figcaption></figure>

Having chosen the correct file and import type you can click the "Start upload"-button to start the import.

## Mapping your data

Having clicked the "Start upload"-button you are presented with a new page. This is where you will map your excel columns to data fields on [categories](https://docs.struct.com/fundamental-concepts/data-model).

As we are importing categories we choose 'Categories' in the Entity type dropdown.

<figure><img src="https://2141378775-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUonpFWM7AJ0xVVXV1tr%2Fuploads%2FitDDkEzXiVSLwZhGdKpl%2Fimage.png?alt=media&#x26;token=233222c3-4422-4d83-a8c2-c3f7ed3a52da" alt=""><figcaption><p>Data mapping</p></figcaption></figure>

Next is mapping the actual data. In this tutorial we map our 'Reference' column to 'Category Alias' as this is the [attribute](https://docs.struct.com/fundamental-concepts/workflows-and-automation) we are using as [identifier](https://docs.struct.com/tutorials/guides/how-to-use-import/broken-reference) that will identify which [categories](https://docs.struct.com/fundamental-concepts/data-model) are parents of which child [categories](https://docs.struct.com/fundamental-concepts/data-model). This is also used as key as it uniquely identifies the [category](https://docs.struct.com/fundamental-concepts/data-model).

The 'Name' column is mapped to 'Category Name (da-DK)', this is the [attribute](https://docs.struct.com/fundamental-concepts/workflows-and-automation) we use as Display name for the [category](https://docs.struct.com/fundamental-concepts/data-model).

We leave 'Product reference' empty, as this [attribute](https://docs.struct.com/fundamental-concepts/workflows-and-automation) will be used to map child [categories](https://docs.struct.com/fundamental-concepts/data-model) to their parents and is not an [attribute](https://docs.struct.com/fundamental-concepts/workflows-and-automation) that exists on the [categories](https://docs.struct.com/fundamental-concepts/data-model).

## The file contains new categories

If no [categories](https://docs.struct.com/fundamental-concepts/data-model) with the key exists, new [categories](https://docs.struct.com/fundamental-concepts/data-model) will be created for each unique key you are trying to import. If the excel spreadsheet contains new [categories](https://docs.struct.com/fundamental-concepts/data-model) you will be prompted to map their parent-child relations and choose the [catalogue](https://docs.struct.com/fundamental-concepts/data-model) to create them under.

<figure><img src="https://2141378775-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUonpFWM7AJ0xVVXV1tr%2Fuploads%2FJQ4GixsO6NamFtfUHK8U%2Fimage.png?alt=media&#x26;token=a655837b-e210-4f37-a2c1-22913e9bb40e" alt=""><figcaption><p>The file contains new categories</p></figcaption></figure>

We are keeping the reference to the parent in the column 'Parent reference' and want to map it to the unique [identifier](https://docs.struct.com/tutorials/guides/how-to-use-import/broken-reference) 'ClothingCategoryId' that exists on the [catalogue](https://docs.struct.com/fundamental-concepts/data-model) 'Product'.

Click the "Next"-button in the right-bottom corner to continue.

## Approve changes

At this point you are shown a 'Review changes'-page. This page will show you the amount of new and updated [categories](https://docs.struct.com/fundamental-concepts/data-model). New [categories](https://docs.struct.com/fundamental-concepts/data-model) will be denoted by having a blue 'New'-tag in the key column whereas existing [categories](https://docs.struct.com/fundamental-concepts/data-model) will show their current value.

[Attributes](https://docs.struct.com/fundamental-concepts/workflows-and-automation) that will be changed are colored green to easily distinguish between [attributes](https://docs.struct.com/fundamental-concepts/workflows-and-automation) that will remain the same and [attribute](https://docs.struct.com/fundamental-concepts/workflows-and-automation) that will change.

<figure><img src="https://2141378775-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUonpFWM7AJ0xVVXV1tr%2Fuploads%2FnIK2XG9MijvaTVKDbR2k%2Fimage.png?alt=media&#x26;token=2814eac9-dd59-4509-bebb-b53e9af2d037" alt=""><figcaption><p>Approve changes</p></figcaption></figure>

In this tutorial we are importing all new [categories](https://docs.struct.com/fundamental-concepts/data-model), so everything is shown as green.&#x20;

Having reviewed the changes you can choose to approve the changes you are satisfied with. Only approved records will be commited.

When you have approved the records you want to keep, click the "Commit import"-button in the bottom-right corner to finalize the import.

{% hint style="danger" %}
You can not approve a child category without approving its parent. Doing this will cause the import to fail as it cannot correctly identify where to put the child.
{% endhint %}

## Resulting category tree

The import from this tutorial will result in the following [category](https://docs.struct.com/fundamental-concepts/data-model) tree under the [catalogue](https://docs.struct.com/fundamental-concepts/data-model) 'Product'.

<figure><img src="https://2141378775-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuUonpFWM7AJ0xVVXV1tr%2Fuploads%2FQbtijDIrVdfOU60hD0B9%2Fimage.png?alt=media&#x26;token=6edccbdd-a8af-4b32-adb0-2d27c772cafc" alt=""><figcaption><p>Category tree</p></figcaption></figure>
