Custom Objects Importer
This package helps with importing commercetools custom objects in JSON format to the commercetools platform. The package is built to be used in conjunction with sphere-node-cli
Configuration
The constructor accepts five arguments:
A required object containing the following values:
apiConfig(Object):AuthMiddlewareoptions 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,view_orders,view_customers,manage_products,manage_orders,manage_customers].batchSize(Number): Amount of custom objects to process concurrently (Optional. Default: 50)continueOnProblems(Boolean): Flag whether to continue processing if an error occurs (Optional. Default: false)An optional logger object having four functions (
info,warn,erroranddebug)
Usage with sphere-node-cli
sphere-node-cliYou can use this package from the sphere-node-cli. In order for the cli to import custom objects, the file to import from must be a valid JSON and follow the following structure:
[{
"container": "Ludus",
"key": "copperKey",
"value": {
"paymentMethod": "Cash",
"paymentID": "1",
"whateverElse": {
"number": 1000
}
}
},
{
"container": "Frobozz",
"key": "jadeKey",
"value": {
"paymentMethod": "cc",
"paymentID": "2",
"whateverElse": {
"digits": [1, 2, 3]
}
}
},
{
"container": "Syrinx",
"key": "crystalKey",
"value": {
"paymentMethod": "new",
"paymentID": "3",
"whateverElse": {
"true": true
}
}
}
...
]Then you can import this file using the cli:
Direct Usage
You can also use this module directly in your Javascript project. To do this, you need to install it:
Then you can use it to import custom objects:
On successful completion, a call to the .summaryReport() method returns a report in the following format:
Note: By default, if a custom object exists, the module tries to build an update action for it, and if no update action can be built, the custom object will be ignored
Last updated