Usage: inventoriesexporter [options]
Export inventories from the commercetools platform.
Options:
--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: "https://api.europe-west1.gcp.commercetools.com"]
--authUrl The host URL of the OAuth API service.
[default: "https://auth.europe-west1.gcp.commercetools.com"]
--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:
https://docs.commercetools.com/http-api-projects-inventory.html#query-inventory
can be used with channelKey flag
--template, -t Path to a CSV template file with headers which should be
exported.
--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"]
JS
For direct usage
import InventoryExporter from '@commercetools/inventories-exporter'
import fs from 'fs'
const apiConfig = {
host: 'https://api.europe-west1.gcp.commercetools.com',
apiUrl: 'https://api.europe-west1.gcp.commercetools.com',
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(
apiConfig,
logger,
exportConfig,
accessToken,
)
const outputStream = fs.createWriteStream('inventories.csv')
// Register error listener
outputStream.on('error', errorHandler)
outputStream.on('finish', () => console.log('done with export'))
inventoryExporter.run(outputStream)