Walkthrough: Exporting catalog and inventory data
This topic describes how to export catalog and inventory data from a Sitecore XC environment.
Sitecore XC provides an application programming interface (API) that you use to export catalog data and inventory sets from a Commerce environment. For example, you can export a Commerce catalog from a development environment and then import it into a different environment, such as a test or a staging environment.
See the Generated data structure section for details on the data structure of the exported data.
To export catalog and inventory data:
- Modify the Internet Information Services (IIS) related settings
- Change the SQL timeout configuration
- Bootstrap the Commerce Engine
- Export a Commerce catalog data set
- Export a Commerce inventory set
Modify the Internet Information Services (IIS) related settings
Before you begin exporting catalog data, you must modify the Internet Information Services (IIS) settings (in the IIS Manager and in the web.config file) to reduce the risk of timeouts from occurring during the data export process. This is important when exporting a very large catalog data set.
To change the IIS configuration and related settings in the web.config file:
-
Start Internet Information Services (IIS) Manager and, in the navigation tree, click Application Pools.
-
On the Application Pools page, click the name of the relevant application pool (for example, CommerceAuthoring_Sc).
-
In the Actions pane, in the Edit Application Pool section, click Advanced Settings and, in the Advance Settings dialog box, set the following parameter values to 0 (zero):
Section Parameter Value CPU Limit Interval (minutes) 0 Process Model Idle Time-out (minutes) 0 Recycling Regular Time Interval (minutes) 0 -
Click OK.
-
Open the
web.configfile for the service you use to export the catalog data (for example,C:\inetpub\wwwroot\CommerceAuthoring_Sc\web.config) and modify the settings marked in bold in the following configuration sample:NoteBefore you change the IIS settings as shown in the following example, take note of their original values so that you know what to set them back to after you have finished exporting catalogs.
NoteOptionally, you can enable logging for collecting information while the catalog export process is running. To do this, open the
config.jsonfile for the service you use to export the catalog data (for example,C:\inetpub\wwwroot\CommerceAuthoring_Sc\wwwroot\config.json) and set the log level values to"Information"."Serilog": { "Using": [ "Serilog.Sinks.Literate", "Serilog.Sinks.File", "Serilog.Sinks.ApplicationInsights" ], "MinimumLevel": { "Default": "Information", "Override": { "Microsoft": "Information", "System": "Information" } },
-
Reset the Internet Information Services.
Change the SQL timeout configuration
Change the SQL timeout configuration to make sure the connection to the SQL database remains open and avoid to allow long processes to complete.
To change the SQL timeout configuration:
-
On the instance of the Authoring service you use to import the catalog data, open the
Plugin.SQL.PolicySet-1.0.0.jsonfile (for example,C:\inetpub\wwwroot\CommerceAuthoring_Sc\wwwroot\data\Environments\Plugin.SQL.PolicySet-1.0.0.json -
Set the value of the
"ConnectTimeout"and"CommandTimeout"properties to"0".NoteTake note of the current property values so that you can set them back to their original values after you have finished importing catalogs.
Bootstrap the Commerce Engine
After you made your changes to the Commerce Engine configuration, bootstrap the Commerce Engine.
Export a Commerce catalog data set
This example is based on the Postman sample provided with the Sitecore Commerce Engine SDK.
The following instructions assume that you have installed and set up the Postman application, imported the sample collections from the Sitecore Commerce Engine SDK, configured your environment, and retrieved a bearer token to access the Commerce Engine API.
As an alternative to using Postman to execute the export catalog API request, this example shows how to use a cURL command in a Bash script.
To export your Commerce XC catalog data set using Postman:
-
In the Postman Collections pane, expand the CatalogAPISamples collection.
-
Open the Catalog - API folder and select the
Export Catalogsrequest ({{ServiceHost}}/{{ShopsApi}}/ExportCatalogs()). -
In the
Environmentfield, specify the Commerce environment that contains the catalog data you need to export. For example, the HabitatAuthoring environment. -
On the Headers tab, provide the following required key values for your deployment:
Header key Value ShopName{{ShopName}}ShopperId{{ShopperId}}Language{{Language}}Currency{{Currency}}Environment{{Environment}}GeoLocation{{GeoLocation}}CustomerId{{CustomerId}}Authorization{{SitecoreIdToken}} -
On the Body tab, modify the export settings based on your specific requirements. The following shows the default settings:
When the
excludeInventoryparameter is set totrue, theExportCatalogcall does not include inventory information. -
To begin the catalog export operation, click Send.
-
Repeat this procedure for each additional catalog that you want to export from your Sitecore Commerce deployment.
NoteIf you have configured logging to collect information during the export operation, set the logging levels back to their original value (for example, from
"Information"back to"Warning").CautionAfter you have finished exporting all your catalogs (and there is no related inventory data to export), you must set the settings you previously changed in IIS Manager and in the web.config file back to their original values.
Otherwise, proceed with exporting inventory data.
Example of a catalog data export using cURL in a Bash script
The following example shows how to export a catalog data set using a cURL command in a Bash script as an alternative to using the Postman tool to send the HTTP request.
Before you execute your script, you must:
-
Update the value
<YOUR HOSTNAME>with the name of the Commerce Engine instance running the Authoring service in your deployment (the default value islocalhost:5000). -
Update the value
in the Authorization request header with a valid token value. -
Update the
Environmentheader key with the name of the Commerce environment that contains the catalog data you need to export. By default, the script specifies the HabitatAuthoring environment. -
Set file permissions by running the
chmod +x <your_base_script>.sh. -
Modify the script to specify your machine name and any other information specific to your deployment environment.
Export a Commerce inventory set
After you have exported your catalog, you can export the associated inventory sets, if you do not have inventory data to export.
This procedure uses the Postman samples provided in the Sitecore Commerce Engine SDK.
As an alternative to using Postman to execute the export inventory API request, this example shows how to use a cURL command in a Bash script.
To export inventory sets data:
-
If the Sitecore Identity token has expired, execute another
GetTokenrequest to get a new token. -
In the Collections pane, expand the InventoryAPISamples collection.
-
Open the Inventory - API folder, and select the
Export Inventory Setsrequest. -
In the Environment field, specify the environment that contains the data that you want to export (for example, the HabitatAuthoring environment).
-
On the Headers tab, provide the following required key values for the deployment:
Header key Value ShopName{{ShopName}}ShopperId{{ShopperId}}Language{{Language}}Currency{{Currency}}Environment{{Environment}}GeoLocation{{GeoLocation}} CustomerId{{CustomerId}}Authorization{{SitecoreIdToken}} -
To begin exporting the inventory sets, click Send.
-
Repeat this procedure for each additional product inventory set that you want to export into your Sitecore Commerce deployment.
CautionAfter you have finished exporting all your catalogs, you must set the settings you previously changed in the IIS Manager and in the web.config file back to their original values.
NoteIf you have configured logging to collect information during the export operation, set the logging levels back to their original value (for example, from
"Information"back to"Warning").
Example of an inventory data export using cURL in a Bash script
The following shows an example of how to export an inventory set using a cURL command in a Bash script as an alternative to using the Postman tool to send the HTTP request.
Before you execute your script, you must:
-
Update the value
<YOUR HOSTNAME>with the name of the Commerce Engine instance running the Authoring service in your deployment (the default value islocalhost:5000). -
Update the value
in the Authorization request header with a valid token value. -
Update the
Environmentheader key with the name of the Commerce environment that contains the data that you need to export. By default, the script specifies the HabitatAuthoring environment. -
Set the file permissions by running the command
chmod +x <your_base_script>.sh. -
Modify the script to specify your machine name and environment, or any other information specific to your deployment.
Generated data structure
When you export catalog or inventory data, the operation generates a ZIP file that contains the data in a specific format. The system expects this same data structure when you import data back into the system.
The ZIP file contains a number of JSON files that define the exported Commerce entities, represented as JSON objects. Each file name identifies the entity type. For example, a file named Category.1.json contains the first page of a list of category entities, in JSON-serialized format.
The catalog export feature only supports full catalog data exports. Catalog data is exported into a .zip file that you can import into the system later. Because all items in a file are imported in parallel, smaller numbers of Commerce entities are batched together in each file, for improved performance.
The ZIP file also includes a Relationships folder that contains a set of JSON files that define the relationships between the entities in the root-level JSON files. The file name indicates the relationship type and the source entity, and the file itself contains a list of JSON objects. Each JSON object defines the source entity, the target entity, and the type of relationship between them.
For example, a file named CatalogToCategory.Habitat_Master.1.json contains information about the relationships between the Habitat_Master catalog and the categories within the catalog: