Category Exporter

A package which exports commercetools categories in JSON format from the commercetools platform.


The constructor accepts two arguments:

  • A required object containing the following values:
    • apiConfig (Object): AuthMiddleware options for authentication on the commercetools platform. (Required. See here)
    • accessToken (String): [Access token] to be used to authenticate requests to API. Requires scope of [view_products, manage_products]. More info on how to get the access token here
    • predicate (String): Query string specifying (where) predicate. More info on predicates here (Optional)
  • An optional logger object having four functions (info, warn, error and debug)


npm install @commercetools/category-exporter --global


Usage: category-exporter [options]
Export categories from the commercetools platform

  --help                     Show help text.                           [boolean]
  --version                  Show version number                       [boolean]
  --output, -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: ""]
  --accessToken              CTP client access token
                             Required scopes: ['view_products', 'manage_products'][string]
  --projectKey, -p           API project key.                         [required]
  --where, -w                specify where predicate
  --logLevel                 Logging level: error, warn, info or debug.
                                                               [default: "info"]
  --prettyLogs               Pretty print logs to the terminal         [boolean]
  --logFile                  Path to file where to save logs.
                                              [default: "category-exporter.log"]

Info on flags

  • The --output flag specifies where to output/save the exported categories. Several notes on this flag:
    • If the file specified already exists, it will be overwritten.
    • The default location for status report logging is the standard output.
    • If no output path is specified, the exported categories will be logged to the standard output as a result, status reports will be logged to a category-exporter.log file in the current directory.
  • The where flag specifies an optional (where) query predicate to be included in the request. This predicate should be wrapped in single quotes ('single quoted predicate'). More info on predicates here


For more direct usage, it is possible to use this module directly:

import CategoryExporter from '@commercetools/category-exporter'
import fs from 'fs'

const options = {
    apiConfig: {
      apiUrl: ''
      host: ''
      project_key: 'PROJECT_KEY',
      credentials: {
        clientId: '*********',
        clientSecret: '*********'
    accessToken: '123456yuhgfdwegh675412wefb4rgb',
    predicate: 'key="my-desired-key"'
const logger = {
  error: console.error,
  warn: console.warn,
  info: console.log,
  debug: console.debug,

const categoryExporter = new CategoryExporter(options, logger)

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

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

results matching ""

    No results matching ""