Use the InStore device CLI to bulk-load your locations and devices to a new environment.
Overview
- Create multiple locations and devices from a JSON or YAML configuration file.
- Avoid conflicts with device dependencies and ordering.
- Securely access APIs.
- Receive console feedback and error logging.
- Verify locations have been added and devices have been registered.
- Optionally integrate the tool into your deployment scripts and automate store setup processes.
Prerequisites
Your development environment should include the following:
- Node.js 22.x or higher
- npm 10.x or higher
Set up your local repository
To set up your local repository for use with the InStore device CLI, complete the following steps:
-
Clone the InStore device CLI repository, for example:
git clone https://github.com/NebulaTerra/instore-device-cli.git cd instore-device-cli
-
Install the required dependencies, for example:
npm install
-
Make the script executable as follows:
chmod +x index.js
-
Create an environment file (.env) with the following variables:
Variable Description API_BASE_URL
Base URL of your REST API. The default is http://localhost:5000. USER_ID
Your user ID for authentication. TENANT_ID
Your tenant ID for authentication. CONNECTION_KEY
Your environment’s connection key for authentication. SCOPES
(Optional) Comma-separated list of the scopes used by your API Client for InStore. TOKEN_EXPIRATION
(Optional) Token expiration in seconds. The default is 3600
).You can use our sample file as a starting point. For example:cp .env.example .env nano .env
-
Test your authentication credentials, for example:
node index.js auth # Or ./index.js auth
Create the configuration file
sample-location.json
that we provide in GitHub. You can use JSON or YAML formats for the file. Not all lines in the sample are required; to view the subset of values we automatically validate against, see the following files in the GitHub src
folder:constants.mjs
: pre-check validationslocations.mjs
: post-check validations
sample-location.json
, verify that a particular device you plan to create is supported by our internal device dictionary. If it is, identify that device by name
in the file. If a device you plan to use is not supported, contact your commercetools representative.To include only supported devices, do the following:
- Log in to the InStore colleague app.
- Go to Manage Devices.
- Select a device of the type you are checking for. Alternatively, add a new device.
- In the Supported Devices field, view the available options.
- Enter the name of the supported device in the
Name
field of your configuration file. Make sure you spell it exactly how it appears in the Supported Devices field.
Configuration components
Most retail locations have the following devices:
- Safe
- Receipt or label printers
- Cash drawers
- Barcode scanners
- Payment terminals or PEDs
- Workstations
The CLI creates devices in a specific order to properly manage dependencies:
- Standard devices, such as safes, PEDs, printers, and scanners are created first.
- Cash drawers are created next, but only after any devices they rely on have already been created. For example, if a printer is required for a cash drawer, the printer must be created before the cash drawer itself.
- Workstations are created last because they reference all other device types.
Alias references
Use alias fields to reference devices. For example, when registering a workstation, you must identify at least a default printer and a default cash drawer as shown in the following example:
{
"name": "iPad Pro",
"type": "Workstation",
"default_PED": "PED-Flagship-01",
"default_cashdrawer": "CASH-Flagship-01",
"default_printer": "PRINT-Flagship-01",
"default_scanner": "SCAN-Flagship-01"
}
PED-Flagship-01
. This is a locally unique value that you specify to temporarily stand in for the device ID, which will not exist until after the device is created. You can look up the ID later in the InStore Center.Run and validate the configuration file
sample-location.json
is the name of your configuration file:node index.js batch sample-location.json
Check your work
-
List all locations:
node index.js list-locations
-
Validate the presence of a specified location:
node index.js validate-location LOCATION_ID
-
Validate the presence of a specified workstation:
node index.js validate-location LOCATION_ID WORKSTATION_ID
-
List all devices for a specified location:
node index.js list-devices LOCATION_ID
JsonData
in subsequent batch commands.InStore device CLI logging
In addition to writing errors to the console, the InStore Device CLI generates detailed logs for each batch operation. Logs are saved as timestamped JSON files in the current directory. There you can view detailed error reporting for failed operations.
For example, errors are logged for safe and cash drawer configurations that are incorrect and for references that are missing or incorrect. Warnings are written for data that is missing but not required.
Troubleshooting InStore device CLI
If you encounter authentication errors, verify the following:
- Your credentials in the .env file are correct.
- Your user account has the proper permissions in the scopes list.
- The API endpoint is correct and accessible.
If you encounter issues during device creation, verify the following:
- All required fields are present.
- Referenced devices have been created.
- Enum values match, including those for device types, statuses, and more.
- The log file provides detailed information about failed attempts.