Inventories Exporter

This package helps in exporting inventories from the commercetools platform in csv and json format


The constructor accepts four arguments:

  • apiConfig (Object): AuthMiddleware options for authentication on the commercetools platform. (Required. See here)
  • An optional logger object having four methods (info, warn, error and verbose)
  • exportConfig (Object): Internal Export configurations
    • delimiter (Object): CSV delimiter
    • format (Object): Export format 'csv', 'json'
    • channelKey (String): Channel key to use as filter for results to export. Useful if you have channel key but not id to build your queryString
    • queryString (String): Predicate to use to filter inventories to export
  • accessToken (String): Access token to be used to authenticate requests to API. Requires scope of [view_products]


npm install @commercetools/inventories-exporter --global


Usage: inventoriesexporter [options]
Export inventories from the commercetools platform.

  --help, -h        Show help text.                                    [boolean]
  --version         Show version number                                [boolean]
  --outputFile, -o  Path to output file.                     [default: "stdout"]
  --apiUrl          The host URL of the HTTP API service.
                                              [default: ""]
  --authUrl         The host URL of the OAuth API service.
                                             [default: ""]
  --delimiter, -d   Used CSV delimiter.                           [default: ","]
  --accessToken     CTP client access token
  --projectKey, -p  API project key.                                  [required]
  --channelKey, -c  Channel key to use as filter for result to export.
                    Useful if you only have channel key but not id.
                    Can be used with the query flag

  --query, -q       Filter query for stocks:
                    can be used with channelKey flag

  --template, -t    Path to a CSV template file with headers which should be
  --format, -f      Format for export [choices: "csv", "json"] [default: "json"]
  --logLevel        Logging level: error, warn, info or verbose.
                                                               [default: "info"]
  --logFile         Path to file where to save logs.
                                           [default: "inventories-exporter.log"]


For direct usage

import InventoryExporter from '@commercetools/inventories-exporter'
import fs from 'fs'

const apiConfig = {
  host: '',
  apiUrl: '',
  projectKey: 'node-test-project',
  credentials: {
    clientId: '123456hgfds',
    clientSecret: '123456yuhgfdwegh675412wefb3rgb',
const accessToken = args.accessToken
const logger = {
  error: console.error,
  warn: console.warn,
  info: console.log,
  verbose: console.debug,
const exportConfig = {
  headerFields: null, // can contain an array of header fields which should be exported
  delimiter: ',',
  format: 'csv,
  queryString: 'description="new stocks"',
const inventoryExporter = new InventoryExporter(

const outputStream = fs.createWriteStream('inventories.csv')

// Register error listener
outputStream.on('error', errorHandler)

outputStream.on('finish', () => console.log('done with export'))

results matching ""

    No results matching ""