Continuing from the last project, we'll add a headless site and integrate it with a Next.js project. Since the process is lengthy, this time we'll focus on adding the headless site and serializing its data for reuse.
![](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F1gcjNpcARFHAz8uDMS13Yr%2F5b31a003b607b416d464193dce3e3e92%2Fjss06.png&w=3840&q=75)
Adding a Headless tenant
In the already prepared instance of XM, we will add a site. First, add a JSS tenant.
![jss01.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F1Ub8BMIkpK9aKNRI3mZi9J%2F69a9389b04bef095324d6a51965b2ea5%2Fjss01.png&w=3840&q=75)
In this case, we will use sitecoredemo-jp.
![jss02.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F2zhEx2NtPi45exWuVhIZ9W%2F31f82e247f01430b25a740e1beff46ff%2Fjss02.png&w=3840&q=75)
Then add a JSS site in the tenant. Right-click on the site and a menu for adding a site will appear.
![jss03.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F68r9KQKHi5sq5275bEHNGI%2Fa47d23599682dd74b94bb9d1a44db6ad%2Fjss03.png&w=3840&q=75)
As for the name of the site, it should be `sitecoredemo-jp`.
![jss04.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F2S9yWxZTrsgJz4FEzu2XkZ%2Fdc04ac7f688598bd114220398e956edd%2Fjss04.png&w=3840&q=75)
The module to be used selects all functions.
![jss05.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2FnCNfLmt6eKt10MFC1PklE%2F84ebe149a3b255733be73a629b76a126%2Fjss05.png&w=3840&q=75)
Once the above steps are completed, the site will be added as follows
![jss06.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F1gcjNpcARFHAz8uDMS13Yr%2F5b31a003b607b416d464193dce3e3e92%2Fjss06.png&w=3840&q=75)
Serialize the created data
In this case, we created a new site, but as with Japanese resources, it would be time-consuming to do the same work again after cleaning up the site. Therefore, we would like to perform serialization so that we can return to the created data at any time.
This is where we will use the Sitecore CLI. Run the following command at the top level of the project to first be able to write to Sitecore from the command line.
dotnet sitecore login --cm https://cm.sitecoredemo.localhost/ --auth https://id.sitecoredemo.localhost/ --allow-write true
The login screen will appear, and you will be asked to confirm that you are allowed to access the system as follows.
![jss07.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F7GiGZfKsnChcTwIasAR1mc%2F2a30dc3c84da084b7836812d8e6fcf28%2Fjss07.png&w=3840&q=75)
Please allow it here. Next, before retrieving the items created by Sitecore, we need to reflect the API key provided by the project on the site. Before executing the command, temporarily change the extension of the json files directly under src to .txt in order to use only the file src\InitItems.module.json. After the change, import the API key using the following command.
dotnet sitecore ser push
![jss08.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F12gzEV2y654on8R1EoQTiS%2F0678b214ec1f69c6601f1325cb4be2bd%2Fjss08.png&w=3840&q=75)
After execution, you will see that the API key has been imported in the content editor.
![jss09.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F3HgRhHbAG1BBf7vFuKv5BA%2F3572f1cdba4b229ad2ba052cfa61292c%2Fjss09.png&w=3840&q=75)
To serialize the data for the site you have just created, change the extensions of the two files you modified before this step back to json.
Since we have created the site in a different form this time than the standard path provided, we will adjust the paths for the two files. The paths below will vary depending on the name of the site created, so refer to the paths deployed in the CMS accordingly.
{
"namespace": "DockerStarter",
"references": [ "InitItems" ],
"items": {
"includes": [
{
"name": "layouts",
"path": "/sitecore/layout/Layouts/Project"
},
{
"name": "placeholders",
"path": "/sitecore/layout/Placeholder Settings/Project/sitecoredemo-jp"
},
{
"name": "renderings",
"path": "/sitecore/layout/Renderings/Project/sitecoredemo-jp"
},
{
"name": "templates",
"path": "/sitecore/templates/Project/sitecoredemo-jp"
}
]
}
}
The file regarding the other content should be changed as follows
{
"namespace": "DockerStarter-Content",
"references": [ "DockerStarter" ],
"items": {
"includes": [
{
"name": "content",
"path": "/sitecore/content/sitecoredemo-jp"
},
{
"name": "media",
"path": "/sitecore/media library/Project/sitecoredemo-jp"
}
]
}
}
After making the above changes, execute the following command
dotnet sitecore ser pull
![jss10.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F7yDbUuizdZowODhe6E4yM0%2F262aae9fdeecc46e51ad855c84794c65%2Fjss10.png&w=3840&q=75)
The data of the created site is serialized and a yaml file is created under the items folder.
![jss11.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F2xwTIhwaQQKhfb3JLTTwXg%2F2c6b039ae80bf51a28960af379463b44%2Fjss11.png&w=1920&q=75)
Add Core database items
All of the above data was processed for serialization with respect to the Master database. Since we are adding Japanese as a language setting, we will also export the items in the core database as serialization. This time, we added the last item in the file `src\InitItems.module.json` in the form of `core-language` as follows.
{
"namespace": "InitItems",
"items" : {
"includes": [
{
"name": "content-root",
"path": "/sitecore/content",
"scope": "singleItem",
"allowedPushOperations": "createAndUpdate"
},
{
"name": "api-key",
"path": "/sitecore/system/Settings/Services/API Keys/DockerStarter",
"scope": "singleItem"
},
{
"name": "core-language",
"path": "/sitecore/system/Languages",
"database": "core"
}
]
}
}
After implementing the above settings, run serialization again.
dotnet sitecore ser pull
Testing Import
Test whether the serialization data created in the above steps can be imported into the new environment. Drop the XM1 environment, clean up the data, and start in a clean environment.
docker-compose down
cd docker
.\clean.ps1
cd ..
docker-compose up -d
After getting up and running, login on the command line. Since you have already logged in once during the above procedure, this time you can simply log in with the following command.
dotnet sitecore login
And next,
dotnet sitecore ser push
We have confirmed that the site has been restored.
![jss12.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F1RZ970tuC8Xc7PLY0XgU39%2F18b05053fce9e0b61b782084f4d70811%2Fjss12.png&w=3840&q=75)
Summary
This time we have added a headless website to the Sitecore side. In the next article, we will review the steps to integrate this site with the Next.js project.