sphere-customer-import
v1.0.5
Published
[![Travis][travis-badge]][travis-url] [![Codecov][codecov-badge]][codecov-url] [![npm][npm-lic-badge]][npm-lic-url] [![semantic-release][semantic-release-badge]][semantic-release-url] [![Commitizen friendly][commitizen-badge]][commitizen-url] [![NPM versi
Downloads
21
Readme
customer-import
A library that helps with importing customers into the Commercetools Platform.
This library is built to be used in conjunction with sphere-node-cli.
Features
- Import customers to your CTP project
- Pre-validate customers using a JSON schema
- generating a password for every new customer
- resolve a customer group name with the corresponding customer group reference
- create a customer group for the given name if none exists yet
- setting a default shipping and billing address
Configuration
The configuration object may contain:
sphereClientConfig
: see the sphere-node-sdk docs for more information on thisdefaultShippingAddress
: Index of the address in the customer'saddresses
list that should be used as the shipping addressdefaultBillingAddress
: Index of the address in the customer'saddresses
list that should be used as the billing address
Usage with sphere-node-cli
You can use the customer import from the command line using the sphere-node-cli
.
In order for the cli to import customer, the file to import from must be JSON and follow the this structure:
{
"customers": [
<customer>,
<customer>,
...
]
}
Then you can import this file using the cli:
sphere-node-cli -t customer -p my-project-key -f /sample_dir/customers.json
You can pass a custom configuration as described above via the -c
operator:
sphere-node-cli -t customer -p my-project-key -f /sample_dir/customers.json -c '{ "defaultShippingAddress": 0, "defaultBillingAddress": 0 }'
Direct usage
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 ct-customer-import --save-dev
Then you can use it to import customers like so:
import CustomerImport from 'ct-customer-import'
const customer = {
email: '<some-email>'
}
const config = {
sphereClientConfig: {
config: {
project_key: <PROJECT_KEY>,
client_id: '*********',
client_secret: '*********'
},
defaultShippingAddress: 0, defaultBillingAddress: 0
}
}
const customerImport = CustomerImport(config)
// load customer groups so they can be resolved to references
customerImport.loadCustomerGroups()
.then(() => customerImport.importCustomer(customer))
.then(() => {
// done importing the customer
// look at the summary to see errors
customerImport.summary
// the summary hast the following structure
// {
// errors: [],
// inserted: [<some-email>],
// successfullImports: 1
// }
})