A package which exports Composable Commerce custom objects in JSON format from commercetools Composable Commerce.
The constructor accepts two arguments:
- A required object containing the following values:
apiConfig(Object):AuthMiddlewareoptions for authentication on commercetools Composable Commerce. (Required. See here)accessToken(String): [Access token] to be used to authenticate requests to API. Requires scope of [view_products,view_orders,view_customers]. More info on how to get the access token herepredicate(String): Query string specifying (where) predicate. More info on predicates here (Optional)
- An optional logger object having four functions (
info,warn,erroranddebug)
npm install @commercetools/custom-objects-exporter --global
Usage: custom-objects-exporter [options]
Export custom objects from commercetools Composable Commerce
Options:
--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: "https://api.europe-west1.gcp.commercetools.com"]
--authUrl The host URL of the OAuth API service.
[default: "https://auth.europe-west1.gcp.commercetools.com"]
--accessToken CTP client access token
--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: "custom-objects-export.log"]
- The
--outputflag specifies where to output/save the exported custom objects. 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 objects will be logged to the standard output as a result, status reports will be logged to a
custom-objects-export.logfile in the current directory.
- The
whereflag 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 CustomObjectsExport from '@commercetools/custom-objects-exporter'
import fs from 'fs'
const options = {
apiConfig: {
apiUrl: 'https://api.europe-west1.gcp.commercetools.com'
host: 'https://auth.europe-west1.gcp.commercetools.com'
project_key: <PROJECT_KEY>,
credentials: {
clientId: '*********',
clientSecret: '*********'
}
},
accessToken: '123456yuhgfdwegh675412wefb3rgb',
predicate: 'key="desired-key"'
}
}
const logger = {
error: console.error,
warn: console.warn,
info: console.log,
debug: console.debug,
}
const CustomObjectsExport = new CustomObjectsExport(options, logger)
// Register error listener
outputStream.on('error', errorHandler)
outputStream.on('finish', () => console.log('done with export'))
CustomObjectsExport.run(outputStream)