MCPcopy Index your code
hub / github.com/contentful/contentful.js

github.com/contentful/contentful.js @v11.12.6

Chat with this repo
repository ↗ · DeepWiki ↗ · release v11.12.6 ↗ · + Follow
166 symbols 461 edges 119 files 25 documented · 15% updated 1d agov11.12.6 · 2026-06-25★ 1,29117 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Contentful Logo

Content Delivery API

JavaScript

Readme · Migration · Advanced · TypeScript · Contributing

Join Contentful Community Slack

Introduction

MIT License NPM jsDelivr Hits NPM downloads GZIP bundle size

JavaScript library for the Contentful Content Delivery API and Content Preview API. It helps you to easily access your content stored in Contentful with your JavaScript applications.

What is Contentful?

Contentful provides content infrastructure for digital teams to power 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 enables developers and content creators to ship their products faster.

Table of contents

Core Features

Supported browsers and Node.js versions

  • Chrome
  • Firefox
  • Edge
  • Safari
  • node.js (LTS)
  • React Native (Metro bundler)

For the minimum supported browser versions, refer to the package.json of this library.

To ensure compatibility across various JavaScript environments, this library is built as an ECMAScript Module (ESM) by default, using the "type": "module" declaration in package.json.

We also offer a bundle for the legacy CommonJS (CJS) require syntax, allowing usage in environments that do not support ESM.

Additionally, there is a bundle available for direct usage within browsers.

For more details on the different variants of this library, see Installation.

Getting started

In order to get started with the Contentful JS library you'll need not only to install it, but also to get credentials which will allow you to have access to your content in Contentful.

Installation

npm install contentful

In a modern environment, you can import this library using:

import * as contentful from 'contentful'

Using in Legacy Environments Without ESM/Import Support

Typically, your system will default to our CommonJS export when you use the require syntax:

const contentful = require('contentful')

If this does not work, you can directly require the CJS-compatible code:

const contentful = require('contentful/dist/contentful.cjs')

Using it directly in the browser

For browsers, we recommend downloading 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:

<script src="https://cdn.jsdelivr.net/npm/contentful@latest/dist/contentful.browser.min.js"></script>

Using contentful@latest will always get you the latest version, but you can also specify a specific version number.

<script src="https://cdn.jsdelivr.net/npm/contentful@9.0.1/dist/contentful.browser.min.js"></script>

The Contentful Delivery library will be accessible via the contentful global variable.

Check the releases page to know which versions are available.

Your first request

The following code snippet is the most basic one you can use to get some content from Contentful with this library:

import * as contentful from 'contentful'
const client = contentful.createClient({
  // This is the space ID. A space is like a project folder in Contentful terms
  space: 'developer_bookshelf',
  // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
  accessToken: '0b7f6x59a0',
})
// This API call will request an entry with the specified ID from the space defined at the top, using a space-specific access token
client
  .getEntry('5PeGS2SoZGSa4GuiQsigQu')
  .then((entry) => console.log(entry))
  .catch((err) => console.log(err))

Check out this JSFiddle version of our Product Catalogue demo app.

Using this library with the Preview API

This library can also be used with the Preview API. In order to do so, you need to use the Preview API Access token, available on the same page where you get the Delivery API token, and specify the host of the preview API, such as:

import * as contentful from 'contentful'
const client = contentful.createClient({
  space: 'developer_bookshelf',
  accessToken: 'preview_0b7f6x59a0',
  host: 'preview.contentful.com',
})

You can find all available methods of our client in our reference documentation.

Authentication

To get your own content from Contentful, an app should authenticate with an OAuth bearer token.

You can create API keys using the Contentful web interface. Go to the app, open the space that you want to access (top left corner lists all the spaces), and navigate to the APIs area. Open the API Keys section and create your first token. Done.

Don't forget to also get your Space ID.

For more information, check the Contentful REST API reference on Authentication.

Cursor-based Pagination

Cursor-based pagination is supported on collection endpoints for entries and assets:

const response = await client.getEntriesWithCursor({ limit: 10 })
console.log(response.items) // Array of items
console.log(response.pages?.next) // Cursor for next page

Use the value from response.pages.next to fetch the next page or response.pages.prev to fetch the previous page.

const nextPageResponse = await client.getEntriesWithCursor({
  limit: 10,
  pageNext: response.pages?.next,
})

console.log(nextPageResponse.items) // Array of items
console.log(nextPageResponse.pages?.next) // Cursor for next page
console.log(nextPageResponse.pages?.prev) // Cursor for prev page

Documentation & References

To help you get the most out of this library, we've prepared all available client configuration options, a reference documentation, tutorials and other examples that will help you learn and understand how to use this library.

Configuration

The createClient method supports several options you may set to achieve the expected behavior:

contentful.createClient({
  ...your config here...
})

The configuration options belong to two categories: request config and response config.

Request configuration options
Name Default Description
accessToken Required. Your CDA access token.
space Required. Your Space ID.
environment 'master' Set the environment that the API key has access to.
host 'cdn.contentful.com' Set the host used to build the request URI's.
basePath '' This path gets appended to the host to allow request urls like https://gateway.example.com/contentful/ for custom gateways/proxies.

Extension points exported contracts — how you extend this code

HeroSkeleton (Interface)
* Two distinct skeletons that share a single field (`internalName`) but each * carry a member-specific field (`headline
test/types/entry-union-links.test-d.ts
CreateContentfulApiParams (Interface)
(no doc)
lib/create-contentful-api.ts
GlobalOptionsParams (Interface)
(no doc)
lib/create-global-options.ts
CreateClientParams (Interface)
(no doc)
lib/contentful.ts
BaseSys (Interface)
(no doc)
lib/types/sys.ts
TypeCatFields (Interface)
(no doc)
test/integration/parseEntries.test.ts
AnimalTypeFields (Interface)
(no doc)
test/unit/make-contentful-api-client-parseentries.test.ts
CtaSkeleton (Interface)
(no doc)
test/types/entry-union-links.test-d.ts

Core symbols most depended-on inside this repo

getEntry
called by 77
lib/types/client.ts
getEntries
called by 63
lib/types/client.ts
createClient
called by 38
lib/contentful.ts
parseEntries
called by 24
lib/types/client.ts
getEntriesWithCursor
called by 20
lib/types/client.ts
normalizeCursorPaginationParameters
called by 18
lib/utils/normalize-cursor-pagination-parameters.ts
checkEnableTimelinePreviewIsAllowed
called by 18
lib/utils/validate-params.ts
get
called by 16
lib/create-contentful-api.ts

Shape

Function 101
Interface 35
Method 24
Class 6

Languages

TypeScript100%

Modules by API surface

lib/create-contentful-api.ts55 symbols
lib/types/client.ts22 symbols
lib/utils/validate-params.ts7 symbols
lib/make-client.ts7 symbols
lib/types/content-type.ts6 symbols
lib/paged-sync.ts6 symbols
test/unit/make-contentful-api-client.test.ts5 symbols
lib/utils/timeline-preview-helpers.ts4 symbols
lib/types/asset.ts4 symbols
test/unit/paged-sync.test.ts3 symbols
test/integration/tests.test.ts3 symbols
lib/utils/validation-error.ts3 symbols

For agents

$ claude mcp add contentful.js \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact