README
Contentful export tool
Contentful 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 is a library that helps you backup your Content Model, Content and Assets or move them to a new Contentful space. It will support Roles & Permissions in a future version.
To import your exported data, please refer to the contentful-import repository.
:exclamation: Usage as CLI
We moved the CLI version of this tool into our 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 export command documentation to learn more about how to use this as command line tool.
:cloud: Pre-requisites && Installation
Pre-requisites
- Node LTS
:cloud: Installation
npm install contentful-export
:hand: Usage
const contentfulExport = require('contentful-export')
const options = {
spaceId: '<space_id>',
managementToken: '<content_management_api_key>',
...
}
contentfulExport(options)
.then((result) => {
console.log('Your space data:', result)
})
.catch((err) => {
console.log('Oh no! Some errors occurred!', err)
})
Querying
To scope your export, you are able to pass query parameters. All search parameters of our API are supported as documented in our API documentation.
const contentfulExport = require('contentful-export')
const options = {
spaceId: '<space_id>',
managementToken: '<content_management_api_key>',
queryEntries: 'content_type=<content_type_id>'
}
contentfulExport(options)
...
The Export tool also support multiple inline queries.
const contentfulExport = require('contentful-export')
const options = {
spaceId: '<space_id>',
managementToken: '<content_management_api_key>',
queryEntries: [
'content_type=<content_type_id>',
'sys.id=<entry_id>'
]
}
contentfulExport(options)
...
queryAssets
uses the same syntax as queryEntries
Export an environment
const contentfulExport = require('contentful-export')
const options = {
spaceId: '<space_id>',
managementToken: '<content_management_api_key>',
environmentId: '<environment_id>'
}
contentfulExport(options)
...
:gear: Configuration options
Basics
[string] [required] spaceId
ID of the space with source data
[string] [default: 'master'] environmentId
ID of the environment in the source space
[string] [required] managementToken
Contentful management API token for the space to be exported
[string] deliveryToken
Contentful Content Delivery API (CDA) token for the space to be exported.
Providing deliveryToken
will export both entries and assets from the
Contentful Delivery API, instead of the Contentful Management API.
This may be useful if you want to export the latest published versions,
as the management API always only exports the entirety of items, with the latest
unpublished content. So if you want to make sure only to see the latest
published changes, provide the deliveryToken
.
Just to clarify: When Contentful Management API always returns the latest version (e.g. 50 in this case):
"createdAt": "2020-01-06T12:00:00.000Z",
"updatedAt": "2020-04-07T11:00:00.000Z",
"publishedVersion": 23,
"publishedAt": "2020-04-05T14:00:00.000Z",
"publishedCounter": 1,
"version": 50,
the Content Delivery API would return the publishedVersion
(23). CDA responses don't include
version number.
Note: Tags are only available on the Contentful Management API, so they will not be exported if you provide a Contenful Delivery Token. Tags is a new feature that not all users have access to.
Output
[string] [default: current process working directory] exportDir
Defines the path for storing the export JSON file
[boolean] [default: true] saveFile
Save the export as a JSON file
[string] contentFile
The filename for the exported data
Filtering
[boolean] [default: false] includeDrafts
Include drafts in the exported entries.
The deliveryToken
option is ignored
when includeDrafts
has been set as true
.
If you want to include drafts, there's no point of getting them through the
Content Delivery API.
[boolean] [default: false] includeArchived
Include archived entries in the exported entries
[boolean] [default: false] skipContentModel
Skip exporting content models
[boolean] [default: false] skipEditorInterfaces
Skip exporting editor interfaces
[boolean] [default: false] skipContent
Skip exporting assets and entries.
[boolean] [default: false] skipRoles
Skip exporting roles and permissions
[boolean] [default: false] skipWebhooks
Skip exporting webhooks
[boolean] [default: false] contentOnly
Only export entries and assets
[array] queryEntries
Only export entries that match these queries
[array] queryAssets
Only export assets that match these queries
[boolean] downloadAssets
Download actual asset files
Connection
[string] [default: 'api.contentful.com'] host
The Management API host
[string] proxy
Proxy configuration in HTTP auth format: host:port
or user:password@host:port
[boolean] rawProxy
Pass proxy config to Axios instead of creating a custom httpsAgent
[number] [default: 1000] maxAllowedLimit
The number of items per page per request
[number] limit
The total number of items to return. Can be used with entries or assets. If not provided, then all entries or assets will be returned. The entries or assets will be ordered using: sys.createdAt,sys.id
.
[object] headers
Additional headers to attach to the requests.
Other
[string] errorLogFile
Full path to the error log file
[boolean] [default: false] useVerboseRenderer
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
Proxy
Unable to connect to Contentful through your proxy? Try to set the rawProxy
option to true
.
contentfulExport({
proxy: 'https://cat:dog@example.com:1234',
rawProxy: true,
...
})
Error: 400 - Bad Request - Response size too big.
Contentful response sizes are limited (find more info in our technical limit docs). In order to resolve this issue, limit the amount of entities received within a single request by setting the maxAllowedLimit
option:
contentfulExport({
proxy: 'https://cat:dog@example.com:1234',
rawProxy: true,
maxAllowedLimit: 50
...
})
:card_file_box: Exported data structure
This is an overview of the exported data:
{
"contentTypes": [],
"entries": [],
"assets": [],
"locales": [],
"tags": [],
"webhooks": [],
"roles": [],
"editorInterfaces": []
}
Note: Tags feature is not available for all users. If you do not have access to this feature, the tags array will always be empty.
:warning: Limitations
- This tool currently does not support the export of space memberships.
- Exported webhooks with credentials will be exported as normal webhooks. Credentials should be added manually afterwards.
- If you have custom UI extensions, you need to reinstall them manually in the new space.
:memo: Changelog
Read the releases page for more information.
:scroll: License
This project is licensed under MIT license