Gathering detailed insights and metrics for contentful-management
Gathering detailed insights and metrics for contentful-management
Gathering detailed insights and metrics for contentful-management
Gathering detailed insights and metrics for contentful-management
contentful-sdk-core
Core modules for the Contentful JS SDKs
contentful-export
this tool allows you to export a space to a JSON dump
contentful-import
this tool allows you to import JSON dump exported by contentful-export
contentful-batch-libs
Library modules used by contentful batch utility CLI tools.
JavaScript library for Contentful's Management API (node & browser)
npm install contentful-management
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
272 Stars
1,800 Commits
97 Forks
66 Watching
26 Branches
269 Contributors
Updated on 26 Nov 2024
Minified
Minified + Gzipped
TypeScript (99.45%)
JavaScript (0.55%)
Cumulative downloads
Total Downloads
Last day
3.1%
96,996
Compared to previous day
Last week
-1%
506,603
Compared to previous week
Last month
23.2%
2,476,113
Compared to previous month
Last year
11.4%
23,719,102
Compared to previous year
53
Readme · Setup · Migration · Changelog · Contributing
What is Contentful?
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.
Browsers and Node.js:
Other browsers should also work, but at the moment we're only running automated tests on the browsers and Node.js versions specified above.
To get started with the Contentful Management JS library you'll need to install it, and then get credentials which will allow you to access your content in Contentful.
Using npm:
1npm install contentful-management
Using yarn:
1yarn add contentful-management
For browsers, we recommend to download the library via npm or yarn to ensure 100% availability.
If you'd like to use a standalone built file you can use the following script tag or download it from jsDelivr, under the dist
directory:
1<script src="https://cdn.jsdelivr.net/npm/contentful-management@latest/dist/contentful-management.browser.min.js"></script>
It's not recommended to use the above URL for production.
Using contentful@latest
will always get you the latest version, but you can also specify a specific version number:
1<!-- Avoid using the following url for production. You can not rely on its availability. --> 2<script src="https://cdn.jsdelivr.net/npm/contentful-management@7.3.0/dist/contentful-management.browser.min.js"></script>
The Contentful Management library will be accessible via the contentfulManagement
global variable.
Check the releases page to know which versions are available.
This library also comes with typings to use with typescript.
To get content from Contentful, an app should authenticate with an OAuth bearer token.
If you want to use this library for a simple tool or a local app that you won't redistribute or make available to other users, you can get an API key for the Management API at our Authentication page.
If you'd like to create an app which would make use of this library but that would be available for other users, where they could authenticate with their own Contentful credentials, make sure to also check out the section about Creating an OAuth Application
You can use the es6 import with the library as follows
1// import createClient directly
2import contentful from 'contentful-management'
3const client = contentful.createClient(
4 {
5 // This is the access token for this space. Normally you get the token in the Contentful web app
6 accessToken: 'YOUR_ACCESS_TOKEN',
7 },
8 { type: 'plain' }
9)
10//....
Beginning with contentful-management@7
this library provides a client which exposes all CMA endpoints in a simple flat API surface, as opposed to the waterfall structure exposed by legacy versions of the SDK.
1const contentful = require('contentful-management') 2const plainClient = contentful.createClient( 3 { 4 accessToken: 'YOUR_ACCESS_TOKEN', 5 }, 6 { type: 'plain' } 7) 8 9const environment = await plainClient.environment.get({ 10 spaceId: '<space_id>', 11 environmentId: '<environment_id>', 12}) 13 14const entries = await plainClient.entry.getMany({ 15 spaceId: '123', 16 environmentId: '', 17 query: { 18 skip: 10, 19 limit: 100, 20 }, 21}) 22 23// With scoped space and environment 24const scopedPlainClient = contentful.createClient( 25 { 26 accessToken: 'YOUR_ACCESS_TOKEN', 27 }, 28 { 29 type: 'plain', 30 defaults: { 31 spaceId: '<space_id>', 32 environmentId: '<environment_id>', 33 }, 34 } 35) 36 37// entries from '<space_id>' & '<environment_id>' 38const entries = await scopedPlainClient.entry.getMany({ 39 query: { 40 skip: 10, 41 limit: 100, 42 }, 43})
You can try and change the above example on Runkit.
The benefits of using the "plain" version of the client, over the legacy version, are:
toPlainObject
function call.spaceId
, environmentId
, and organizationId
when initializing the client.
defaults
and omit specifying these params in actual CMA methods calls.The following code snippet is an example of the legacy client interface, which reads and writes data as a sequence of nested requests:
1const contentful = require('contentful-management') 2const client = contentful.createClient({ 3 accessToken: 'YOUR_ACCESS_TOKEN', 4}) 5 6// Get a space with the specified ID 7client.getSpace('spaceId').then((space) => { 8 // Get an environment within the space 9 space.getEnvironment('master').then((environment) => { 10 // Get entries from this environment 11 environment.getEntries().then((entries) => { 12 console.log(entries.items) 13 }) 14 // Get a content type 15 environment.getContentType('product').then((contentType) => { 16 // Update its name 17 contentType.name = 'New Product' 18 contentType.update().then((updatedContentType) => { 19 console.log('Update was successful') 20 }) 21 }) 22 }) 23})
Starting @contentful/app-sdk@4
you can use this client to make requests
from your apps built for Contentful.
A dedicated Adapter grants your apps access to the supported space-environment scoped entities without compromising on security as you won't need to expose a management token, and without coding any additional backend middleware.
1const contentfulApp = require('@contentful/app-sdk') 2const contentful = require('contentful-management') 3 4contentfulApp.init((sdk) => { 5 const cma = contentful.createClient( 6 { apiAdapter: sdk.cmaAdapter }, 7 { 8 type: 'plain', 9 defaults: { 10 environmentId: sdk.ids.environmentAlias ?? sdk.ids.environment, 11 spaceId: sdk.ids.space, 12 }, 13 } 14 ) 15 16 // ...rest of initialization code 17})
Please Note
Requests issued by the App SDK adapter will count towards the same rate limiting quota as the ones made by other APIs exposed by App SDK (e.g., Space API). Ultimately, they will all fall into the same bucket as the calls performed by the host app (i.e., Contentful web app, Compose, or Launch).
contentful-management
and not contenful-management
¯\_(ツ)_/¯http
- Our library is supplied as node and browser version. Most non-node environments, like React Native, act like a browser. To force using of the browser version, you can require it via: const { createClient } = require('contentful-management/dist/contentful-management.browser.min.js')
To help you get the most out of this library, we've prepared reference documentation, tutorials and other examples that will help you learn and understand how to use this library.
The createClient
method supports several options you may set to achieve the expected behavior:
1contentful.createClient({
2 ... your config here ...
3})
apiAdapter
is not set)Your CMA access token.
'api.contentful.com'
)Set the host used to build the request URI's.
'upload.contentful.com'
)Set the host used to build the upload related request uri's.
This path gets appended to the host to allow request urls like https://gateway.example.com/contentful/
for custom gateways/proxies.
undefined
)Custom agent to perform HTTP requests. Find further information in the axios request config documentation.
undefined
)Custom agent to perform HTTPS requests. Find further information in the axios request config documentation.
{}
)Additional headers to attach to the requests. We add/overwrite the following headers:
application/vnd.contentful.management.v1+json
sdk contentful-management.js/1.2.3; platform node.js/1.2.3; os macOS/1.2.3
(Automatically generated)undefined
)Axios proxy configuration. See the axios request config documentation for further information about the supported values.
true
)By default, this library is retrying requests which resulted in a 500 server error and 429 rate limit response. Set this to false
to disable this behavior.
function (level, data) {}
)Errors and warnings will be logged by default to the node or browser console. Pass your own log handler to intercept here and handle errors, warnings and info on your own.
function (config) {}
)Interceptor called on every request. Takes Axios request config as an arg. Default does nothing. Pass your own function to log any desired data.
function (response) {}
)Interceptor called on every response. Takes Axios response object as an arg. Default does nothing. Pass your own function to log any desired data.
new RestAdapter(configuration)
)An Adapter
that can be utilized to issue requests. It defaults to a RestAdapter
initialized with provided configuration.
Please Note
The Adapter will take precedence over the other options. Therefore, ensure you're providing the Adapter all the information it needs to issue the request (e.g., host or auth headers)
0
)Maximum number of requests per second.
1
-30
(fixed number of limit),'auto'
(calculated limit based on your plan),'0%'
- '100%'
(calculated % limit based on your plan)The Contentful's JS library reference documents what objects and methods are exposed by this library, what arguments they expect and what kind of data is returned.
Most methods also have examples which show you how to use them.
You can start by looking at the top level contentfulManagement
namespace.
The ContentfulClientAPI
namespace defines the methods at the Client level which allow you to create and get spaces.
The ContentfulSpaceAPI
namespace defines the methods at the Space level which allow you to create and get entries, assets, content types and other possible entities.
The Entry
, Asset
and ContentType
namespaces show you the instance methods you can use on each of these entities, once you retrieve them from the server.
From version 1.0.0 onwards, you can access documentation for a specific version by visiting
https://contentful.github.io/contentful-management.js/contentful-management/<VERSION>
Read the Contentful for JavaScript page for Tutorials, Demo Apps, and more information on other ways of using JavaScript with Contentful
This library is a wrapper around our Contentful Management REST API. Some more specific details such as search parameters and pagination are better explained on the REST API reference, and you can also get a better understanding of how the requests look under the hood.
This project strictly follows Semantic Versioning by use of semantic-release.
This means that new versions are released automatically as fixes, features or breaking changes are released.
You can check the changelog on the releases page.
We appreciate any help on our repositories. For more details about how to contribute see our CONTRIBUTING.md document.
This repository is published under the MIT license.
We want to provide a safe, inclusive, welcoming, and harassment-free space and experience for all participants, regardless of gender identity and expression, sexual orientation, disability, physical appearance, socioeconomic status, body size, ethnicity, nationality, level of experience, age, religion (or lack thereof), or other identity markers.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
25 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
all changesets reviewed
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
1 existing vulnerabilities detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More