https://github.com/commercetools/sphere-product-type-import
A library that helps with importing product-types into the Commercetools Platform.
https://github.com/commercetools/sphere-product-type-import
Last synced: over 1 year ago
JSON representation
A library that helps with importing product-types into the Commercetools Platform.
- Host: GitHub
- URL: https://github.com/commercetools/sphere-product-type-import
- Owner: commercetools
- License: mit
- Created: 2016-04-18T09:40:14.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-04-17T04:24:25.000Z (about 3 years ago)
- Last Synced: 2025-02-25T14:56:09.989Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 1.04 MB
- Stars: 2
- Watchers: 19
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README

# sphere-product-type-import
[![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 version][npm-image]][npm-url]
A library that helps with importing [product-types](http://dev.commercetools.com/http-api-projects-productTypes.html) into the [Commercetools Platform](http://www.commercetools.com/).
This library is built to be used in conjunction with [sphere-node-cli](https://github.com/sphereio/sphere-node-cli).
Table of Contents
=================
* [Features](#features)
* [Configuration](#configuration)
* [Usage](#usage)
* [Usage with sphere-node-cli](#usage-with-sphere-node-cli)
* [Direct usage](#direct-usage)
* [Contributing](#contributing)
## Features
- Import product types to your CTP project
- Pre-validate product types using a [JSON schema](https://github.com/sphereio/sphere-product-type-import/blob/master/src/product-type-import.js#L7)
## Configuration
The configuration object may contain:
- `sphereClientConfig`: see the [sphere-node-sdk docs](http://sphereio.github.io/sphere-node-sdk/) for more information on this
## Usage
### Usage with `sphere-node-cli`
You can use the product type import from the command line using the [`sphere-node-cli`](https://github.com/sphereio/sphere-node-cli).
In order for the cli to import product types, the file to import from must be JSON and follow the this structure:
```
{
"productTypes": [
,
,
...
]
}
```
Then you can import this file using the cli:
```
sphere-node-cli -t productType -p my-project-key -f /sample_dir/productTypes.json
```
You can pass a custom configuration as described above via the `-c` operator followed by a JSON String that represents your configuration
### 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 sphere-product-type-import --save-dev
```
Then you can use it to import product types like so:
```
import ProductTypeImport from 'sphere-product-type-import'
const productType = {
name: '',
description: ''
}
const config = {
importerConfig: {
continueOnProblems: false
},
sphereClientConfig: {
config: {
project_key: ,
client_id: '*********',
client_secret: '*********'
}
}
}
const productTypeImport = ProductTypeImport(config)
productTypeImport.importProductType(productType)
.then(() => {
// done importing the productType
// look at the summary to see errors
productTypeImport.summary
// the summary hast the following structure
// {
// errors: [],
// inserted: [],
// successfulImports: 1
// }
})
```
When there is an error during processing productTypes, process will by default save this error to `summary.errors` array and reject. If the configuration flag `importerConfig.continueOnProblems` is set to `true` the importer will only push error to summary and then continue with next productType.
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) file for info on how to contribute to this library
[travis-badge]: https://img.shields.io/travis/sphereio/sphere-product-type-import.svg?style=flat-square
[travis-url]: https://travis-ci.org/sphereio/sphere-product-type-import
[codecov-badge]: https://img.shields.io/codecov/c/github/sphereio/sphere-product-type-import.svg?style=flat-square
[codecov-url]: https://codecov.io/github/sphereio/sphere-product-type-import
[npm-lic-badge]: https://img.shields.io/npm/l/sphere-product-type-import.svg?style=flat-square
[npm-lic-url]: http://spdx.org/licenses/MIT
[semantic-release-badge]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square
[semantic-release-url]: https://github.com/semantic-release/semantic-release
[commitizen-badge]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square
[commitizen-url]: http://commitizen.github.io/cz-cli/
[npm-url]: https://npmjs.org/package/sphere-product-type-import
[npm-image]: http://img.shields.io/npm/v/sphere-product-type-import.svg?style=flat-square
[npm-downloads-image]: https://img.shields.io/npm/dt/sphere-product-type-import.svg?style=flat-square