sphere-product-type-export v1.0.0
sphere-product-type-export
A library that helps with exporting product-types from the Commercetools Platform. This library is built to be used in conjunction with sphere-node-cli.
Features
- Export product types from your CTP project
- Creates 2 files - product type / attributes matrix and attributes list - that can be used to reimport product types
Configuration
The configuration object may contain:
config: configuration object that may contain the following optionsdelimiter: the delimiter to be used in the csv (default:,)outputFolder(required): the folder used to store the exported product types and attributesexportFormat(optional): output format, supported arecsv,xlsx(default:csv)encoding(optional): encoding used when saving data, supported encodings are listed here (default:utf8)where(optional): where predicate used to filter exported productTypes. More info hereincludeProductTypeInAttributes(optional): flag to be used when all the attibutes need to be exported
sphereClientConfig: see the sphere-node-sdk docs for more information on this
Usage
This module can be used as a command line tool as well as a node.js module.
CLI
Before using this module in the command line, install it with a global flag.
npm install sphere-product-type-export -gCommand
Command accepts following arguments:
- The
--projectKeyor-pparameter is required and contains a project key which should be used when exporting productTypes. - The
--outputFolderor-oparameter is required and contains a path to an output folder where the output will be saved. - The
--accessTokenor-tparameter tells module if it should use access token instead of clientId and clientSecret. - The
--sphereHostparameter tells module whether to use a different API URL. - The
--sphereProtocolparameter tells module whether to use a different protocol. - The
--whereor-wparameter can be used for filtering productTypes before exporting. - The
--exportFormatparameter specifies in which format (CSV or XLSX) shoud it save exported productTypes (default is CSV). - The
--delimiteror-dparameter specifies what delimiter should be used when exporting to CSV (default is ','). - The
--compressOutputor-cparameter specifies whether to archive export files after export is done (default is false). - The
--encodingparameter specifies in which encoding should be exported CSV files (default is utf8). - The
includeProductTypeInAttributesflag to be used when all the attibutes need to be exported.
To export all productTypes in the CSV format we can run this command:
product-type-export -p project-key -o tmpOutput
Export successful!
{
"errors": [],
"exported": {
"productTypes": 3,
"attributes": 18
}
}In the tmp folder there will be created two files attributes.csv and products-to-attributes.csv which describe exported productTypes.
JS
If you want more control, you can also use this library directly in JavaScript. To do this you first need to install it:
npm install sphere-product-type-export --saveThen you can use it to export product types like so:
export ProductTypeExport from 'sphere-product-type-export'
const config = {
sphereClientConfig: {
config: {
project_key: <PROJECT_KEY>,
client_id: '*********',
client_secret: '*********'
}
},
config: {
outputFolder: '',
delimiter: '', // default: ,
compressOutput: '', // default: false
exportFormat: '', // default: csv
encoding: '', // default: utf8
where: '', // default: ''
}
}
const productTypeExport = ProductTypeExport(config)
productTypeExport.run()
.then(() => {
// done exporting the productType
// look at the summary to see errors
productTypeExport.summary
// the summary hast the following structure
// {
// errors: [],
// exported: [<some-name>],
// successfulExports: 1
// }
})Contributing
See CONTRIBUTING.md file for info on how to contribute to this library
2 years ago
4 years ago
5 years ago
5 years ago
7 years ago
7 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
