Tailwind Logo

Importing items using Sitecore CLI

CLI

Published: 2022-08-31

Previously, we added the Next.js template to the project, but at this stage Sitecore has no data, so we get an error. Therefore, we would like to import the sample data using Sitecore CLI.

Install Sitecore CLI

For the data import tool, we will use the Sitecore CLI. The installation procedure has already been described in the following blog.

This time we will run the command at the top of the project.

PowerShell
dotnet new tool-manifest
dotnet nuget add source -n Sitecore https://sitecore.myget.org/F/sc-packages/api/v3/index.json
dotnet tool install Sitecore.CLI

This completes the installation.

cli01.png

Initialization

Perform initialization to use Sitecore CLI.

PowerShell
dotnet sitecore init

Subsequent review of the list will install the required plug-ins.

PowerShell
dotnet sitecore plugin list
cli02.png

This completes the configuration, but please add a .gitignore setting to prevent the following files from being copied to the GitHub repository.

Plain Text
# may contain OAuth secrets, do not commit
.sitecore/user.json

# NuGet cache for Sitecore CLI
.sitecore/package-cache/

To check if the Sitecore CLI connects to Sitecore running in a container, execute the following command

PowerShell
dotnet sitecore login --cm https://cm.sitecoredemo.localhost --auth https://id.sitecoredemo.localhost --allow-write true
dotnet sitecore index schema-populate                                                                                   
cli03.png

We have confirmed that Sitecore can be accessed from the command line.

Prepare items

The items to be imported can be obtained from the following GitHub repository.

  • https://github.com/SitecoreJapan/Sitecoredemo.Docker

The target files are as follows

  • src/*.json file
  • src/items folder

For the above two, copy the files to the same hierarchy. After copying, the files should look like this

cli04.png

Importing to Sitecore

The above items can be imported by using the following commands.

PowerShell
dotnet sitecore ser push
cli05.png

The items have been imported, and when you access Sitecore's content editor you should see the following

cli06.png

Summary

In this article, we have performed a batch import of sample items to be used in a Next.js template using the Sitecore CLI. In the next article, we will show you how to connect Next.js and Sitecore to display pages.

Tags