### Install and Run Test Source: https://github.com/contentful/contentful-management.js/blob/master/test/output-integration/browser/README.md Execute these commands to install dependencies and run the test suite for the browser demo. ```sh npm install && npm run test ``` -------------------------------- ### Plain Client API Example Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/README.md Example of using the plain client to get an entry. This is the recommended client type for modern development. ```javascript const client = createClient({ accessToken: 'token' }) const entry = await client.entry.get({ spaceId: 'space123', environmentId: 'master', entryId: 'entry456' }) ``` -------------------------------- ### Install Latest Contentful Management with npm Source: https://github.com/contentful/contentful-management.js/blob/master/MIGRATION.md Use this command to install the latest version of the contentful-management library using npm. ```bash npm install contentful-management@latest ``` -------------------------------- ### Install Canary Version Source: https://github.com/contentful/contentful-management.js/blob/master/README.md Use this command to install a pre-release version of the library that includes features not yet released. This version may not be stable. ```bash npm install contentful-management@canary ``` -------------------------------- ### Legacy Client API Example Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/README.md Example of using the legacy client to get an entry. This client type is deprecated and not recommended for new projects. ```javascript const client = createClient({ accessToken: 'token' }, { type: 'legacy' }) const space = await client.getSpace('space123') const environment = await space.getEnvironment('master') const entry = await environment.getEntry('entry456') ``` -------------------------------- ### Client Configuration Example Source: https://github.com/contentful/contentful-management.js/blob/master/README.md Basic structure for configuring the Contentful Management client with various options. ```js createClient({ ... your config here ... }) ``` -------------------------------- ### Install Contentful Management Library with yarn Source: https://github.com/contentful/contentful-management.js/blob/master/README.md Install the contentful-management library using yarn. Yarn is an alternative package manager for Node.js. ```bash yarn add contentful-management ``` -------------------------------- ### Client Configuration with Custom Defaults Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/configuration.md This example shows how to set default space, environment, and organization IDs using a separate options object. This is the recommended approach for setting defaults. ```javascript const client = createClient( { accessToken: 'your_token' }, { defaults: { spaceId: 'myspace123', environmentId: 'master', organizationId: 'myorg456' // Optional } } ) // Pass empty object - defaults are applied const entries = await client.entry.getMany({}) const env = await client.environment.get({}) ``` -------------------------------- ### Get Environment Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/spaces-and-environments.md Fetches a single environment within a specific space. ```APIDOC ## GET /spaces/{spaceId}/environments/{environmentId} ### Description Fetch a single environment. ### Method GET ### Endpoint /spaces/{spaceId}/environments/{environmentId} ### Parameters #### Path Parameters - **spaceId** (string) - Required - Parent space ID - **environmentId** (string) - Required - Environment identifier ### Response #### Success Response (200) - **name** (string) - The name of the environment ### Response Example ```json { "name": "Master Environment" } ``` ``` -------------------------------- ### Get All Release Actions Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/webhooks-and-releases.md Fetches all release actions for a given release. ```APIDOC ## GET /release-actions ### Description Fetches all release actions for a given release. ### Method GET ### Endpoint /spaces/{spaceId}/environments/{environmentId}/releases/{releaseId}/release-actions ### Parameters #### Path Parameters - **spaceId** (string): Space identifier - **environmentId** (string): Environment identifier - **releaseId** (string): Release identifier #### Query Parameters - **query.limit** (number): Max release actions to return ### Response #### Success Response (200) - **CollectionProp**: Paginated release action collection ### Response Example ```json { "sys": { "type": "Array" }, "total": 1, "skip": 0, "limit": 10, "items": [ { "sys": { "id": "action123", "type": "ReleaseAction", "createdAt": "2024-01-02T11:05:00Z" }, "type": "update", "entity": { "sys": { "id": "entry123", "type": "Entry" } } } ] } ``` ``` -------------------------------- ### get() Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/spaces-and-environments.md Fetches a specific environment alias by its ID within a given space. ```APIDOC ## get() ### Description Fetch an environment alias. ### Method GET ### Endpoint /spaces/{spaceId}/environment-aliases/{aliasId} ### Parameters #### Path Parameters - **spaceId** (string) - Required - Parent space ID - **aliasId** (string) - Required - Alias identifier ### Response #### Success Response (200) - **environmentAlias** (EnvironmentAliasProps) - The environment alias object ``` -------------------------------- ### get() Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/entries-and-assets.md Fetches a single asset by its ID. ```APIDOC ## get() [Asset] ### Description Fetches a single asset by its ID. ### Method GET ### Endpoint /spaces/{space_id}/environments/{environment_id}/assets/{asset_id} ### Parameters #### Path Parameters - **spaceId** (string): Space identifier - **environmentId** (string): Environment identifier - **assetId** (string): Asset identifier ### Request Example ```javascript const asset = await client.asset.get({ spaceId: 'space123', environmentId: 'master', assetId: 'asset789' }) console.log(asset.fields.file['en-US'].url) ``` ### Response #### Success Response (200) - **AssetProps**: Asset object with file references #### Response Example ```json { // Asset object } ``` ``` -------------------------------- ### Create Client with Basic Authentication (ES6) Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/client-factory.md Instantiate a Contentful Management API client using an access token. This is the most common way to start interacting with the API. Requires the 'contentful-management' package. ```javascript import { createClient } from 'contentful-management' const client = createClient({ accessToken: 'YOUR_CONTENT_MANAGEMENT_API_TOKEN' }) // Fetch a space const space = await client.space.get({ spaceId: 'space123' }) console.log(space.name) ``` -------------------------------- ### Legacy Client Interface Example Source: https://github.com/contentful/contentful-management.js/blob/master/README.md Demonstrates the deprecated legacy client interface for making nested requests to manage content. Use this for older projects or migration purposes. ```js import { createClient } from 'contentful-management' const client = createClient( { accessToken: 'YOUR_ACCESS_TOKEN', }, { type: 'legacy' }, ) // Get a space with the specified ID client.getSpace('spaceId').then((space) => { // Get an environment within the space space.getEnvironment('master').then((environment) => { // Get entries from this environment environment.getEntries().then((entries) => { console.log(entries.items) }) // Get a content type environment.getContentType('product').then((contentType) => { // Update its name contentType.name = 'New Product' contentType.update().then((updatedContentType) => { console.log('Update was successful') }) }) }) }) ``` -------------------------------- ### Get All Environments Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/spaces-and-environments.md Fetches all environments within a given space, with options for limiting and skipping results for pagination. ```APIDOC ## GET /spaces/{spaceId}/environments ### Description Fetch all environments in a space. ### Method GET ### Endpoint /spaces/{spaceId}/environments ### Parameters #### Path Parameters - **spaceId** (string) - Required - Parent space ID #### Query Parameters - **query.limit** (number) - Optional - Max environments to return - **query.skip** (number) - Optional - Environments to skip ### Response #### Success Response (200) - **items** (array) - Paginated collection of environment objects ### Response Example ```json { "items": [ { "name": "Master" }, { "name": "Staging" } ] } ``` ``` -------------------------------- ### Create Personal Access Token Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/tags-and-access-control.md Example of creating a personal access token with specified name, scopes, and an expiration date. Ensure scopes are minimal and necessary. ```javascript const token = await client.personalAccessToken.create({}, { name: 'GitHub Actions - Content Sync', scopes: ['content_management_manage'], expiresAt: '2025-06-15T00:00:00Z' }) ``` -------------------------------- ### Get All Spaces Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/spaces-and-environments.md Fetches all spaces within an organization, supporting pagination with limit and skip parameters. ```javascript const result = await client.space.getMany({ query: { limit: 50 } }) result.items.forEach(space => console.log(space.name)) ``` -------------------------------- ### Get All Releases Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/webhooks-and-releases.md Fetches all releases within a given space and environment, with optional filtering and pagination. ```APIDOC ## GET /releases ### Description Fetches all releases within a given space and environment, with optional filtering and pagination. ### Method GET ### Endpoint /spaces/{spaceId}/environments/{environmentId}/releases ### Parameters #### Path Parameters - **spaceId** (string): Space identifier - **environmentId** (string): Environment identifier #### Query Parameters - **query.limit** (number): Max releases to return - **query.status** (string, optional): Filter by status ('DRAFT', 'SCHEDULED', 'PUBLISHED', 'FAILED') ### Response #### Success Response (200) - **CollectionProp**: Paginated release collection ### Response Example ```json { "sys": { "type": "Array" }, "total": 2, "skip": 0, "limit": 10, "items": [ { "sys": { "id": "release123", "type": "Release", "createdAt": "2024-01-01T12:00:00Z", "updatedAt": "2024-01-01T12:05:00Z" }, "title": "Q1 2024 Release", "description": "Major feature release for Q1", "version": 1 } ] } ``` ``` -------------------------------- ### Get Release Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/webhooks-and-releases.md Fetches a specific release by its ID within a given space and environment. ```APIDOC ## GET /releases/{releaseId} ### Description Fetches a specific release by its ID within a given space and environment. ### Method GET ### Endpoint /spaces/{spaceId}/environments/{environmentId}/releases/{releaseId} ### Parameters #### Path Parameters - **spaceId** (string): Space identifier - **environmentId** (string): Environment identifier - **releaseId** (string): Release identifier ### Response #### Success Response (200) - **ReleaseProps**: Release object ### Response Example ```json { "sys": { "id": "release123", "type": "Release", "createdAt": "2024-01-01T12:00:00Z", "updatedAt": "2024-01-01T12:00:00Z", "publishedAt": "2024-01-01T12:05:00Z" }, "title": "Q1 2024 Release", "description": "Major feature release for Q1", "version": 1 } ``` ``` -------------------------------- ### Get All Content Types Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/content-types-and-locales.md Fetches a paginated collection of all content types within an environment. ```APIDOC ## GET /content_types ### Description Fetches all content types in an environment. ### Method GET ### Endpoint /spaces/{spaceId}/environments/{environmentId}/content_types ### Parameters #### Path Parameters - **spaceId** (string) - Required - Space identifier - **environmentId** (string) - Required - Environment identifier #### Query Parameters - **limit** (number) - Optional - Max content types to return - **skip** (number) - Optional - Content types to skip ### Response #### Success Response (200) - **total** (number) - Total number of content types - **items** (Array) - Paginated collection of content types ### Request Example ```javascript const result = await client.contentType.getMany({ spaceId: 'space123', environmentId: 'master', query: { limit: 100 } }) console.log(`Total content types: ${result.total}`) ``` ``` -------------------------------- ### Get All Environments in a Space Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/spaces-and-environments.md Fetches all environments within a given space, supporting pagination with limit and skip parameters. ```javascript const result = await client.environment.getMany({ spaceId: 'space123' }) result.items.forEach(env => console.log(env.name)) ``` -------------------------------- ### get() Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/entries-and-assets.md Fetches a single entry by its ID. You can specify a locale and control the depth of included linked resources. ```APIDOC ## GET /spaces/{space_id}/environments/{environment_id}/entries/{entry_id} ### Description Fetches a single entry by its ID. Supports locale-specific fetching and inclusion of linked resources. ### Method GET ### Endpoint /spaces/{space_id}/environments/{environment_id}/entries/{entry_id} ### Parameters #### Query Parameters - **query.locale** (string, optional) - Specific locale to fetch (default: all) - **query.include** (number, optional) - Include linked resources (0-10) ### Response #### Success Response (200) - **sys** (object) - Entry metadata including ID, content type, etc. - **fields** (object) - Entry data organized by locale. ### Request Example ```javascript await client.entry.get({ spaceId: 'space123', environmentId: 'master', entryId: 'entry456' }) ``` ``` -------------------------------- ### Get All Spaces Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/spaces-and-environments.md Fetches all spaces within the organization, with options for limiting the number of results and pagination. ```APIDOC ## GET /spaces ### Description Fetches all spaces in the organization. ### Method GET ### Endpoint /spaces ### Parameters #### Query Parameters - **query.limit** (number) - Optional - Max spaces to return - **query.skip** (number) - Optional - Spaces to skip for pagination ### Response #### Success Response (200) - **items** (array) - Collection of space objects ### Response Example ```json { "items": [ { "name": "Space 1" }, { "name": "Space 2" } ] } ``` ``` -------------------------------- ### Offset-based Pagination Example Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/plain-client.md Fetch entries using offset-based pagination by specifying `limit` and `skip` in the query parameters. The response includes items, total count, limit, and skip values. ```typescript const entries = await client.entry.getMany({ spaceId: 'space123', environmentId: 'master', query: { limit: 100, skip: 0 } }) // Response includes: // - items: Entry[] // - total: number // - limit: number // - skip: number ``` -------------------------------- ### Cursor-based Pagination Example Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/plain-client.md Utilize cursor-based pagination with `getManyWithCursor` for efficient fetching of large datasets. The response indicates if a next page exists and provides a cursor. ```typescript const result = await client.entry.getManyWithCursor({ spaceId: 'space123', environmentId: 'master', query: { limit: 50 } }) // Response includes: // - items: Entry[] // - pageLimit: number // - pageItemCount: number // - hasNextPage: boolean // - nextPageCursor: string (if hasNextPage) ``` -------------------------------- ### Fetch a Webhook Definition Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/webhooks-and-releases.md Use the `get` method to retrieve a specific webhook's configuration using its ID and the space ID. ```javascript const webhook = await client.webhook.get({ spaceId: 'space123', webhookId: 'webhook123' }) console.log(`URL: ${webhook.url}`) console.log(`Active: ${webhook.active}`) ``` -------------------------------- ### Publish a Release Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/webhooks-and-releases.md Publish a release after fetching it. This action publishes all entities within the release. It requires the release object obtained from a 'get' operation. ```javascript let release = await client.release.get({ spaceId: 'space123', environmentId: 'master', releaseId: 'release123' }) release = await client.release.publish( { spaceId: 'space123', environmentId: 'master', releaseId: 'release123' }, release ) console.log('Released at:', release.sys.publishedAt) ``` -------------------------------- ### Create Client Using Environment Variables Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/configuration.md Illustrates how to initialize the client by reading access tokens, space IDs, and environment IDs from environment variables. ```javascript const client = createClient({ accessToken: process.env.CONTENTFUL_ACCESS_TOKEN, space: process.env.CONTENTFUL_SPACE_ID, environment: process.env.CONTENTFUL_ENVIRONMENT_ID }) ``` -------------------------------- ### Basic Client Initialization and Fetching Entries Source: https://github.com/contentful/contentful-management.js/blob/master/README.md Initialize the client and demonstrate fetching a specific environment and multiple entries with query parameters. ```javascript import { createClient } from 'contentful-management' const client = createClient({ accessToken: 'YOUR_ACCESS_TOKEN', }) const environment = await client.environment.get({ spaceId: '', environmentId: '', }) const entries = await client.entry.getMany({ spaceId: '123', environmentId: '', query: { skip: 10, limit: 100, }, }) ``` -------------------------------- ### Get Latest SDK Version Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/README.md Check the latest version of the contentful-management SDK using npm. This command helps in staying updated with the latest features and changes. ```bash npm view contentful-management version ``` -------------------------------- ### Prevent Prepublish Build on Local npm Install Source: https://github.com/contentful/contentful-management.js/blob/master/SETUP.md Configure the 'prepublish' script to avoid building when running 'npm install' locally. This prevents unnecessary build steps during local development or installation. ```json "prepublish": "in-publish && npm run build || not-in-publish" ``` -------------------------------- ### Create Client with Default Parameters Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/configuration.md Demonstrates how to create a client with default spaceId and environmentId, making them optional in subsequent method calls. Shows how to override defaults. ```javascript const client = createClient( { accessToken: 'token' }, { defaults: { spaceId: 'myspace', environmentId: 'staging' } } ) // Both of these work const a = await client.entry.getMany({}) // Uses defaults const b = await client.entry.getMany({ spaceId: 'otherspace' // Overrides default }) ``` -------------------------------- ### Implement Network Error Fallback Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/errors.md Provide a fallback mechanism for network errors like 'ECONNREFUSED' or 'ENOTFOUND'. This example logs a message and suggests implementing alternative strategies. ```javascript async function makeRequestWithNetworkFallback(fn) { try { return await fn() } catch (error) { if (error.code === 'ECONNREFUSED' || error.code === 'ENOTFOUND') { console.error('Network error, attempting with alternate connection') // Implement fallback (cached data, alternate endpoint, etc.) } throw error } } ``` -------------------------------- ### Basic Contentful SDK Usage Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/README.md Demonstrates how to create a client and fetch a space, environment, and entries. Ensure you replace 'YOUR_ACCESS_TOKEN' with your actual token. ```javascript import { createClient } from 'contentful-management' const client = createClient({ accessToken: 'YOUR_ACCESS_TOKEN' }) // Fetch a space const space = await client.space.get({ spaceId: 'space123' }) // Fetch an environment const environment = await client.environment.get({ spaceId: 'space123', environmentId: 'master' }) // List all entries in an environment const entries = await client.entry.getMany({ spaceId: 'space123', environmentId: 'master' }) entries.items.forEach(entry => { console.log(entry.fields) }) ``` -------------------------------- ### Minimal Client Configuration Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/configuration.md This is the most basic configuration, requiring only an access token to initialize the client. ```javascript import { createClient } from 'contentful-management' const client = createClient({ accessToken: 'your_access_token' }) ``` -------------------------------- ### Raw HTTP Access - GET Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/plain-client.md Performs a direct GET request to the Contentful API. Useful for fetching resources when a specific resource method is not available or for custom endpoints. ```APIDOC ## GET ### Description Direct GET request to the Contentful API. ### Method GET ### Endpoint `/url` ### Parameters #### Path Parameters - **url** (string) - Required - Full API URL path #### Query Parameters - **config** (RawAxiosRequestConfig) - Optional - Axios request configuration ### Response #### Success Response (200) - **T** (unknown) - Resolves to the response data ### Request Example ```javascript const space = await client.raw.get('/spaces/space123') ``` ``` -------------------------------- ### Raw HTTP GET Request Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/plain-client.md Use `raw.get` for direct GET requests to the Contentful API. Provide the full API URL and optional Axios request configuration. ```javascript const space = await client.raw.get('/spaces/space123') ``` -------------------------------- ### Scoped Client Initialization and Fetching Entries Source: https://github.com/contentful/contentful-management.js/blob/master/README.md Initialize a client instance with default space and environment IDs, then fetch entries without specifying them in the call. ```javascript // With scoped space and environment const scopedClient = createClient( { accessToken: 'YOUR_ACCESS_TOKEN', }, { defaults: { spaceId: '', environmentId: '', }, }, ) // entries from '' & '' const entries = await scopedClient.entry.getMany({ query: { skip: 10, limit: 100, }, }) ``` -------------------------------- ### Create a New Release Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/webhooks-and-releases.md Create a new release with a title and optional description. Requires space and environment IDs. ```javascript const release = await client.release.create( { spaceId: 'space123', environmentId: 'master' }, { title: 'Q1 2024 Release', description: 'Major feature release for Q1' } ) ``` -------------------------------- ### Get Release Action Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/webhooks-and-releases.md Fetches a specific release action by its ID. ```APIDOC ## GET /release-actions/{releaseActionId} ### Description Fetches a specific release action by its ID. ### Method GET ### Endpoint /spaces/{spaceId}/environments/{environmentId}/releases/{releaseId}/release-actions/{releaseActionId} ### Parameters #### Path Parameters - **spaceId** (string): Space identifier - **environmentId** (string): Environment identifier - **releaseId** (string): Release identifier - **releaseActionId** (string): Release action identifier ### Response #### Success Response (200) - **ReleaseActionProps**: Release action object ``` -------------------------------- ### Create Client with Default Space and Environment Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/client-factory.md Initialize a client with an access token, allowing subsequent requests to implicitly use a preset space ID and environment ID. This simplifies calls when working with a specific space and environment. ```javascript import { createClient } from 'contentful-management' const client = createClient({ accessToken: 'YOUR_TOKEN' }) // Fetch environment with preset space ID const environment = await client.environment.get({ spaceId: 'space123', environmentId: 'staging' }) ``` -------------------------------- ### Initialize Client via Script Tag Source: https://github.com/contentful/contentful-management.js/blob/master/README.md Access the global `contentfulManagement` variable to create a client instance with your access token. ```javascript const client = contentfulManagement.createClient({ accessToken: 'YOUR_ACCESS_TOKEN', }) ``` -------------------------------- ### Initialize Client with CommonJS Require Source: https://github.com/contentful/contentful-management.js/blob/master/README.md Use CommonJS `require` syntax to import the library and create a client instance. ```javascript // import createClient directly const contentful = require('contentful-management'); const client = contentful.createClient({ // This is the access token for this space. Normally you get the token in the Contentful web app accessToken: 'YOUR_ACCESS_TOKEN', }) ``` -------------------------------- ### Get Many Locales Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/content-types-and-locales.md Fetches all locales available within a specific environment. ```APIDOC ## GET /locales ### Description Fetch all locales in an environment. ### Method GET ### Endpoint /spaces/{space_id}/environments/{environment_id}/locales ### Parameters #### Path Parameters - **spaceId** (string): Space identifier - **environmentId** (string): Environment identifier ### Response #### Success Response (200) - **CollectionProp** (object): Collection of locales ### Response Example ```json { "sys": { "type": "Array" }, "total": 2, "skip": 0, "limit": 100, "items": [ { "sys": { "type": "Locale", "id": "en-US", "version": 1, "createdAt": "2023-01-01T10:00:00Z", "updatedAt": "2023-01-01T10:00:00Z", "space": { "sys": { "type": "Link", "linkType": "Space", "id": "space123" } }, "environment": { "sys": { "type": "Link", "linkType": "Environment", "id": "master" } } }, "name": "English (United States)", "code": "en-US", "default": true, "contentManagementApi": true, "contentDeliveryApi": true }, { "sys": { "type": "Locale", "id": "de", "version": 1, "createdAt": "2023-01-01T10:05:00Z", "updatedAt": "2023-01-01T10:05:00Z", "space": { "sys": { "type": "Link", "linkType": "Space", "id": "space123" } }, "environment": { "sys": { "type": "Link", "linkType": "Environment", "id": "master" } } }, "name": "German", "code": "de", "default": false, "contentManagementApi": true, "contentDeliveryApi": true } ] } ``` ### Request Example ```javascript const result = await client.locale.getMany({ spaceId: 'space123', environmentId: 'master' }) result.items.forEach(locale => { console.log(`${locale.code}: ${locale.name}`) }) ``` ``` -------------------------------- ### Get Locale Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/content-types-and-locales.md Fetches a single locale by its ID within a specific environment. ```APIDOC ## GET /locales/{localeId} ### Description Fetch a locale by ID. ### Method GET ### Endpoint /spaces/{space_id}/environments/{environment_id}/locales/{locale_id} ### Parameters #### Path Parameters - **spaceId** (string): Space identifier - **environmentId** (string): Environment identifier - **localeId** (string): Locale identifier (e.g., 'en-US', 'de') ### Response #### Success Response (200) - **LocaleProps** (object): Locale definition ### Response Example ```json { "sys": { "type": "Locale", "id": "en-US", "version": 1, "createdAt": "2023-01-01T10:00:00Z", "updatedAt": "2023-01-01T10:00:00Z", "space": { "sys": { "type": "Link", "linkType": "Space", "id": "space123" } }, "environment": { "sys": { "type": "Link", "linkType": "Environment", "id": "master" } } }, "name": "English (United States)", "code": "en-US", "default": true, "contentManagementApi": true, "contentDeliveryApi": true } ``` ### Request Example ```javascript const locale = await client.locale.get({ spaceId: 'space123', environmentId: 'master', localeId: 'en-US' }) console.log(`${locale.name} (${locale.code})`) ``` ``` -------------------------------- ### Create Client with Environment Variable Token Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/tags-and-access-control.md Demonstrates the recommended way to initialize the Contentful client using an access token stored in an environment variable for security. ```javascript // ✓ Good: Token from environment const client = createClient({ accessToken: process.env.CONTENTFUL_ACCESS_TOKEN }) ``` -------------------------------- ### Initialize Client with ES6 Import Source: https://github.com/contentful/contentful-management.js/blob/master/README.md Use ES6 import syntax to directly import the `createClient` function and initialize the client. ```javascript // import createClient directly import { createClient } from 'contentful-management' const client = createClient({ // This is the access token for this space. Normally you get the token in the Contentful web app accessToken: 'YOUR_ACCESS_TOKEN', }) ``` -------------------------------- ### Get Many Access Tokens Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/tags-and-access-control.md Fetches all access tokens for a given space. ```APIDOC ## GET /spaces/{space_id}/access_tokens ### Description Fetches all access tokens for a given space. ### Method GET ### Endpoint /spaces/{space_id}/access_tokens ### Parameters #### Path Parameters - **spaceId** (string) - Required - Space identifier #### Query Parameters - **limit** (number) - Optional - Max tokens to return - **skip** (number) - Optional - Tokens to skip ### Response #### Success Response (200) - **CollectionProp** (object) - Token collection (passwords are not included) ``` -------------------------------- ### Get Tag Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/tags-and-access-control.md Fetches a specific tag by its ID within a given space. ```APIDOC ## GET /spaces/{space_id}/tags/{tag_id} ### Description Fetches a specific tag by its ID within a given space. ### Method GET ### Endpoint /spaces/{space_id}/tags/{tag_id} ### Parameters #### Path Parameters - **spaceId** (string) - Required - Space identifier - **tagId** (string) - Required - Tag identifier ### Response #### Success Response (200) - **TagProps** (object) - Tag object with visibility and metadata ``` -------------------------------- ### Create a Webhook Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/webhooks-and-releases.md Use the `create` method to set up a new webhook. Specify the target URL, the events to listen for (topics), and optionally configure authentication, headers, and retry policies. ```javascript const webhook = await client.webhook.create( { spaceId: 'space123' }, { name: 'Content Update Webhook', url: 'https://myapp.com/webhooks/contentful', active: true, topics: ['Entry.save', 'Entry.publish', 'Asset.delete'], headers: { 'X-Custom-Header': 'value', 'Authorization': 'Bearer token123' }, retryPolicy: { maxRetries: 5, delayMs: 100, backoffMultiplier: 2, maxDelayMs: 60000 } } ) ``` -------------------------------- ### Get Content Type Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/content-types-and-locales.md Fetches a specific content type definition by its ID. ```APIDOC ## GET /content_types/{contentTypeId} ### Description Fetches a specific content type definition by its ID. ### Method GET ### Endpoint /spaces/{spaceId}/environments/{environmentId}/content_types/{contentTypeId} ### Parameters #### Path Parameters - **spaceId** (string) - Required - Space identifier - **environmentId** (string) - Required - Environment identifier - **contentTypeId** (string) - Required - Content type identifier ### Response #### Success Response (200) - **fields** (Array) - Content type schema with fields ### Request Example ```javascript const blogPost = await client.contentType.get({ spaceId: 'space123', environmentId: 'master', contentTypeId: 'blog-post' }) console.log('Fields:', blogPost.fields.map(f => f.name)) ``` ``` -------------------------------- ### Get Many Teams Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/organizations-and-teams.md Fetches all teams within a specified organization. Supports pagination. ```APIDOC ## GET /organizations/{organizationId}/teams ### Description Fetches all teams within a specified organization. Supports pagination. ### Method GET ### Endpoint /organizations/{organizationId}/teams ### Parameters #### Path Parameters - **organizationId** (string) - Required - The identifier of the organization. #### Query Parameters - **query.limit** (number) - Optional - Maximum number of teams to return. - **query.skip** (number) - Optional - Number of teams to skip. ### Response #### Success Response (200) - **items** (Array) - A paginated collection of team objects. - **total** (number) - The total number of teams available. - **skip** (number) - The number of teams skipped. - **limit** (number) - The maximum number of teams returned. ### Request Example ```javascript const result = await client.team.getMany({ organizationId: 'org123', query: { limit: 100 } }) result.items.forEach(team => { console.log(team.name) }) ``` ``` -------------------------------- ### Create Client with Default Parameters Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/plain-client.md Instantiate the client with default space and environment IDs. These defaults can then be omitted from subsequent method calls. ```typescript const client = createClient( { accessToken: 'token' }, { defaults: { spaceId: 'space123', environmentId: 'master' } } ) // spaceId and environmentId are optional const entries = await client.entry.getMany({}) ``` -------------------------------- ### Create Client with Hardcoded Token (Not Recommended) Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/tags-and-access-control.md Illustrates an insecure practice of hardcoding an access token directly into the client initialization. This should be avoided. ```javascript // ✗ Bad: Token hardcoded const client = createClient({ accessToken: 'abc123...' }) ``` -------------------------------- ### Get Many Tags Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/tags-and-access-control.md Fetches a paginated collection of all tags within a given space. ```APIDOC ## GET /spaces/{space_id}/tags ### Description Fetches a paginated collection of all tags within a given space. ### Method GET ### Endpoint /spaces/{space_id}/tags ### Parameters #### Path Parameters - **spaceId** (string) - Required - Space identifier #### Query Parameters - **limit** (number) - Optional - Max tags to return - **skip** (number) - Optional - Tags to skip ### Response #### Success Response (200) - **CollectionProp** (object) - Paginated tag collection ``` -------------------------------- ### Get Content Types with Cursor Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/content-types-and-locales.md Fetches content types using cursor-based pagination. ```APIDOC ## GET /content_types (cursor-based) ### Description Fetch content types with cursor-based pagination. ### Method GET ### Endpoint /spaces/{spaceId}/environments/{environmentId}/content_types ### Parameters #### Path Parameters - **spaceId** (string) - Required - Space identifier - **environmentId** (string) - Required - Environment identifier #### Query Parameters - **limit** (number) - Optional - Items per page - **cursor** (string) - Optional - Cursor for pagination ### Response #### Success Response (200) - **items** (Array) - Cursor-paginated collection - **nextCursor** (string) - Cursor for the next page ``` -------------------------------- ### create() Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/spaces-and-environments.md Creates a new environment within a space. The environment ID is auto-generated. Optionally, it can clone settings from an existing environment. ```APIDOC ## create() ### Description Create an environment with auto-generated ID. ### Method POST ### Endpoint /spaces/{spaceId}/environments ### Parameters #### Path Parameters - **spaceId** (string) - Required - Parent space ID #### Request Body - **name** (string) - Required - Environment name - **sourceEnvironmentId** (string) - Optional - ID of the environment to clone from ### Request Example ```json { "name": "staging" } ``` ### Response #### Success Response (200) - **environment** (EnvironmentProps) - The created environment object ``` -------------------------------- ### Create Client with Custom Default Parameters Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/client-factory.md Configure the client with custom default parameters for spaceId and environmentId using the 'defaults' option. This allows omitting these parameters in subsequent method calls. ```javascript import { createClient } from 'contentful-management' const client = createClient( { accessToken: 'YOUR_TOKEN' }, { defaults: { spaceId: 'space123', environmentId: 'master' } } ) // spaceId and environmentId are optional now const entries = await client.entry.getMany({}) ``` -------------------------------- ### Client Configuration with Default Space and Environment Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/configuration.md Configure the client with default space and environment IDs to avoid specifying them in every request. This simplifies subsequent API calls. ```javascript const client = createClient({ accessToken: 'your_token', space: 'myspace123', environment: 'master' }) // Now spaceId and environmentId are optional const entries = await client.entry.getMany({}) ``` -------------------------------- ### Create Client with Custom HTTP Configuration Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/client-factory.md Initialize a client with custom HTTP settings, including API host, timeout, retry attempts, and custom headers. Useful for specific network configurations or advanced request control. ```javascript import { createClient } from 'contentful-management' const client = createClient({ accessToken: 'YOUR_TOKEN', host: 'api.example.com', timeout: 60000, maxRetries: 3, headers: { 'X-Custom-Header': 'value' } }) ``` -------------------------------- ### Get Team Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/organizations-and-teams.md Fetches a specific team within an organization. Requires organization and team identifiers. ```APIDOC ## GET /organizations/{organizationId}/teams/{teamId} ### Description Fetches a specific team within an organization. Requires organization and team identifiers. ### Method GET ### Endpoint /organizations/{organizationId}/teams/{teamId} ### Parameters #### Path Parameters - **organizationId** (string) - Required - The identifier of the organization. - **teamId** (string) - Required - The identifier of the team. ### Response #### Success Response (200) - **name** (string) - The name of the team. - **description** (string) - The description of the team. - **sys** (object) - System properties of the team. ### Request Example ```javascript const team = await client.team.get({ organizationId: 'org123', teamId: 'team456' }) console.log(`Team: ${team.name}`) ``` ``` -------------------------------- ### Get Many Organization Memberships Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/organizations-and-teams.md Fetches all members within a specified organization. Supports pagination. ```APIDOC ## GET /organizations/{organizationId}/memberships ### Description Fetches all members within a specified organization. Supports pagination. ### Method GET ### Endpoint /organizations/{organizationId}/memberships ### Parameters #### Path Parameters - **organizationId** (string) - Required - The identifier of the organization. #### Query Parameters - **query.limit** (number) - Optional - Maximum number of memberships to return. - **query.skip** (number) - Optional - Number of memberships to skip. ### Response #### Success Response (200) - **items** (Array) - A paginated collection of membership objects. - **total** (number) - The total number of memberships available. - **skip** (number) - The number of memberships skipped. - **limit** (number) - The maximum number of memberships returned. ### Request Example ```javascript const result = await client.organizationMembership.getMany({ organizationId: 'org123', query: { limit: 100 } }) result.items.forEach(member => { console.log(`${member.user.sys.id}: ${member.role}`) }) ``` ``` -------------------------------- ### create() Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/spaces-and-environments.md Creates a new environment alias within a space. This alias will point to a specified target environment. ```APIDOC ## create() ### Description Create an environment alias. ### Method POST ### Endpoint /spaces/{spaceId}/environment-aliases ### Parameters #### Path Parameters - **spaceId** (string) - Required - Parent space ID #### Request Body - **environment** (object) - Required - Link to the target environment - **sys** (object) - Required - **type** (string) - Required - Must be 'Link' - **linkType** (string) - Required - Must be 'Environment' - **id** (string) - Required - Target environment ID ### Request Example ```json { "environment": { "sys": { "type": "Link", "linkType": "Environment", "id": "staging" } } } ``` ### Response #### Success Response (200) - **environmentAlias** (EnvironmentAliasProps) - The created environment alias object ``` -------------------------------- ### Get Many Personal Access Tokens Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/tags-and-access-control.md Fetches all personal access tokens for the current user. ```APIDOC ## GET /personal_access_tokens ### Description Fetches all personal access tokens for the current user. ### Method GET ### Endpoint /personal_access_tokens ### Parameters #### Query Parameters - **limit** (number) - Optional - Max tokens to return - **skip** (number) - Optional - Tokens to skip ### Response #### Success Response (200) - **CollectionProp** (object) - Token collection ``` -------------------------------- ### create() Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/entries-and-assets.md Creates an asset with a file reference. The file must be uploaded separately. ```APIDOC ## create() [Asset] ### Description Creates an asset with a file reference. The file must be uploaded separately. ### Method POST ### Endpoint /spaces/{space_id}/environments/{environment_id}/assets ### Parameters #### Path Parameters - **spaceId** (string): Space identifier - **environmentId** (string): Environment identifier #### Request Body - **rawData.fields.file** (object): File reference with upload URL and details. - **rawData.fields.title** (string): Asset title. - **rawData.fields.description** (string): Optional - Asset description. ### Request Example ```javascript const asset = await client.asset.create( { spaceId: 'space123', environmentId: 'master' }, { fields: { title: { 'en-US': 'Product Image' }, file: { 'en-US': { contentType: 'image/png', fileName: 'product.png', uploadFrom: { sys: { type: 'Link', linkType: 'Upload', id: 'upload123' } } } } } } ) ``` ### Response #### Success Response (200) - **AssetProps**: Created asset #### Response Example ```json { // Created asset object } ``` ``` -------------------------------- ### Client Configuration with Proxy Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/configuration.md Set up the client to use a proxy server for all HTTPS requests by providing a `httpsAgent` configured with `https-proxy-agent`. ```javascript import https from 'https' import HttpsProxyAgent from 'https-proxy-agent' const agent = new HttpsProxyAgent('http://proxy.example.com:3128') const client = createClient({ accessToken: 'your_token', httpsAgent: agent }) ``` -------------------------------- ### Get Organization Membership Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/organizations-and-teams.md Fetches a specific organization membership by its ID. Requires both organization and membership identifiers. ```APIDOC ## GET /organizations/{organizationId}/memberships/{membershipId} ### Description Fetches a specific organization membership by its ID. Requires both organization and membership identifiers. ### Method GET ### Endpoint /organizations/{organizationId}/memberships/{membershipId} ### Parameters #### Path Parameters - **organizationId** (string) - Required - The identifier of the organization. - **membershipId** (string) - Required - The identifier of the membership. ### Response #### Success Response (200) - **role** (string) - The role assigned to the membership. - **user** (object) - User object associated with the membership. - **sys** (object) - System properties of the membership. ### Request Example ```javascript const membership = await client.organizationMembership.get({ organizationId: 'org123', membershipId: 'member456' }) console.log(`Role: ${membership.role}`) console.log(`User: ${membership.user.sys.id}`) ``` ``` -------------------------------- ### Client Configuration for Development (Insecure) Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/configuration.md Configure the client for development environments by specifying a custom host, base path, and enabling insecure SSL connections. Use with caution and never in production. ```javascript const client = createClient({ accessToken: 'your_token', host: 'localhost:3000', basePath: '/api/v1', insecure: true // Allow self-signed certificates }) ``` -------------------------------- ### Get an Asset Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/entries-and-assets.md Fetches a single asset by its ID. The returned asset object includes file references. ```javascript const asset = await client.asset.get({ spaceId: 'space123', environmentId: 'master', assetId: 'asset789' }) console.log(asset.fields.file['en-US'].url) ``` -------------------------------- ### Create Client using Browser Script Tag Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/client-factory.md Initialize the Contentful Management client in a browser environment using a CDN-provided script. The client is exposed globally via the `contentfulManagement` object. ```html ``` -------------------------------- ### Migrate from Legacy Contentful Client Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/README.md Compares the legacy client's method for creating a client and fetching data with the modern plain client's approach. The plain client uses a more structured API for accessing spaces, environments, and entries. ```javascript // Before (Legacy): const client = createClient({ accessToken: 'token' }, { type: 'legacy' }) const space = await client.getSpace('space123') const environment = await space.getEnvironment('master') const entries = await environment.getEntries() // After (Plain): const client = createClient({ accessToken: 'token' }) const space = await client.space.get({ spaceId: 'space123' }) const environment = await client.environment.get({ spaceId: 'space123', environmentId: 'master' }) const entries = await client.entry.getMany({ spaceId: 'space123', environmentId: 'master' }) ``` -------------------------------- ### Get All Locales Source: https://github.com/contentful/contentful-management.js/blob/master/_autodocs/api-reference/content-types-and-locales.md Retrieves a collection of all locales within a specified environment. Requires space and environment IDs. ```javascript const result = await client.locale.getMany({ spaceId: 'space123', environmentId: 'master' }) result.items.forEach(locale => { console.log(`${locale.code}: ${locale.name}`) }) ```