contentful-import
Version:
this tool allows you to import JSON dump exported by contentful-export
204 lines (145 loc) • 7.12 kB
Markdown
[](https://www.npmjs.com/package/contentful-import)
[](https://travis-ci.org/contentful/contentful-import)
[](https://codecov.io/gh/contentful/contentful-import)
[](https://david-dm.org/contentful/contentful-import)
[](https://david-dm.org/contentful/contentful-import#info=devDependencies)
[](https://github.com/semantic-release/semantic-release) [](http://standardjs.com/)
[](https://www.contentful.com) provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.
This library helps you to import files generated by [contentful-export](https://github.com/contentful/contentful-export) to a destination space.
> We moved the CLI version of this tool into our [Contentful CLI](https://github.com/contentful/contentful-cli). This allows our users to use and install only one single CLI tool to get the full Contentful experience.
>
> Please have a look at the [Contentful CLI import command documentation](https://github.com/contentful/contentful-cli/tree/master/docs/space/import) to learn more about how to use this as command line tool.
- Node LTS
```bash
npm install contentful-import
```
```javascript
const contentfulImport = require('contentful-import')
const options = {
content: {entries:..., contentTypes:..., locales:...},
spaceId: '<space_id>',
managementToken: '<content_management_api_key>',
...
}
contentfulImport(options)
.then(() => {
console.log('Data imported successfully')
})
.catch((err) => {
console.log('Oh no! Some errors occurred!', err)
})
```
or
```javascript
const contentfulImport = require('contentful-import')
const options = {
contentFile: '/path/to/result/of/contentful-export.json',
spaceId: '<space_id>',
managementToken: '<content_management_api_key>',
...
}
contentfulImport(options)
.then(() => {
console.log('Data imported successfully')
})
.catch((err) => {
console.log('Oh no! Some errors occurred!', err)
})
```
```javascript
const contentfulImport = require('contentful-import')
const options = {
contentFile: '/path/to/result/of/contentful-export.json',
spaceId: '<space_id>',
managementToken: '<content_management_api_key>',
environmentId: '<environment_id>',
...
}
contentfulImport(options)
...
```
ID of the space to import into
ID of the environment in the destination space
Contentful management API token for the space to be imported to
Path to JSON file that contains data to be import to your space
Content to import. Needs to match the expected structure (See below)
### Filtering
#### `contentModelOnly` [boolean] [default: false]
Import content types only
#### `skipContentModel` [boolean] [default: false]
Skip importing of content types and locales
#### `skipLocales` [boolean] [default: false]
Skip importing of locales
#### `skipContentPublishing` [boolean] [default: false]
Skips content publishing. Creates content but does not publish it
### Connection
#### `host` [string] [default: 'api.contentful.com']
The Management API host
#### `proxy` [string]
Proxy configuration in HTTP auth format: `host:port` or `user:password@host:port`
#### `rawProxy` [boolean]
Pass proxy config to Axios instead of creating a custom httpsAgent
### Other
#### `errorLogFile` [string]
Full path to the error log file
#### `useVerboseRenderer` [boolean] [default: false]
Display progress in new lines instead of displaying a busy spinner and the status in the same line. Useful for CI.
## :rescue_worker_helmet: Troubleshooting
Unable to connect to Contentful through your Proxy? Try to set the `rawProxy` option to `true`.
```javascript
contentfulImport({
proxy: 'https://cat:dog@example.com:1234',
rawProxy: true,
...
})
```
## :card_file_box: Expected input data structure
The data to import should be structured like this:
```json
{
"contentTypes": [],
"entries": [],
"assets": [],
"locales": [],
"webhooks": [],
"roles": [],
"tags": [],
"editorInterfaces": []
}
```
Note: `tags` are not available for all users. If you do not have access to this feature, any tags included in your import data will be skipped.
- Both source space and destination space must share the same content model structure. In order to achieve that, please use [contentful-migration](https://www.npmjs.com/package/contentful-migration).
- Content transformations are also not supported, please use [contentful-migration](https://www.npmjs.com/package/contentful-migration).
- Entities existence are determined based on their ID:
* If an entity does not exist in the destination space, it will be created.
* If an entity already exists in the destination space, it will be updated.
- Publishing strategy:
* If an entity is in draft, it will be created as draft in the destination space.
* If an entity is published and has pending changes (updated) in the source space, it will be published with the latest changes in the destination space.
## :warning: Limitations
- This tool currently does **not** support the import of space memberships.
- This tool currently does **not** support the import of roles.
- This tool is expecting the target space to have the same default locale as your previously exported space.
- Imported webhooks with credentials will be imported as normal webhooks. Credentials should be added manually afterwards.
- Imported webhooks with secret headers will be imported without these headers. Secret headers should be added manuall afterwards.
- If you have custom UI extensions, you need to reinstall them manually in the new space.
## :memo: Changelog
Read the [releases](https://github.com/contentful/contentful-import/releases) page for more information.
## :scroll: License
This project is licensed under MIT license
[1]: https://www.contentful.com