sphere-customer-import

1.0.5 • Public • Published

customer-import

Travis Codecov npm semantic-release Commitizen friendly NPM version

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 this
  • defaultShippingAddress: Index of the address in the customer's addresses list that should be used as the shipping address
  • defaultBillingAddress: Index of the address in the customer's addresses 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
  // }
})

Package Sidebar

Install

npm i sphere-customer-import

Weekly Downloads

4

Version

1.0.5

License

MIT

Unpacked Size

367 kB

Total Files

23

Last publish

Collaborators

  • commercetools-admin
  • emmenko
  • hajoeichler
  • yanns
  • tdeekens
  • timonrey
  • vineetkumarkushwaha
  • markusazer
  • jherey
  • danrleyt
  • jenschude
  • chukwuemeka
  • philippspo