Home Reference Source Repository

Typedef

Static Public Summary
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public
public

Webhook: *

public

Static Public

public ApiKey: ApiKey source

Properties:

NameTypeAttributeDescription
sys Object

System metadata

name string
description string
update() function(): Promise<ApiKey>

Sends an update to the server with any changes made to the object's properties

delete() function(): Promise

Deletes this object on the server

toPlainObject function(): Object

Returns this Api Key as a plain JS object

Example:


// require contentful-management
var contentfulManagement = require('contentful-management')
var client = contentfulManagement.createClient({
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN'
})

var space = await client.getSpace('SPACE_ID')

//=======================================================================================================
// You can get an ApiKey object by
//
// 1. Creating one
//
// var apiKey = await space.createApiKey({})
//
// OR
//
// 2. Get an existing one
//
// var apiKey = await space.getApiKey('API_KEY_ID')
//=======================================================================================================

// we'll use option 2
var apiKey = await space.getApiKey('API_KEY_ID')

// Example updating an APIKey
apiKey.name = 'New name'
apiKey.update()
.then(apiKey => console.log(apiKey.name))

// Example deleting an ApiKey
apiKey.delete()
.catch(err => console.log(err))

public ApiKeyCollection: ApiKeyCollection source

Properties:

NameTypeAttributeDescription
total number

Total amount of records in the server

skip number

A starting point of the collection

limit number

Amount of records in collection

items ApiKey[]

Array of ApiKey

toPlainObject function(): Object

Returns this Api Key collection as a plain JS object

Example:


// require contentful-management
var contentfulManagement = require('contentful-management')
var client = contentfulManagement.createClient({
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN'
})

var space = await client.getSpace('SPACE_ID')

//get all the api keys
space.getApiKeys()
.then(apiKeys => console.log(apiKeys.items))

public Asset: Asset source

Properties:

NameTypeAttributeDescription
sys Object

Standard system metadata with additional asset specific properties

sys.locale string

If present, indicates the locale which this asset uses

fields Object

Object with content for each field

fields.title string

Title for this asset

fields.description string

Description for this asset

fields.file Object

File object for this asset

fields.file.fileName Object

Name for the file

fields.file.contentType string

Mime type for the file

fields.file.upload string

Url where the file is available to be downloaded from, into the Contentful asset system. After the asset is processed this field is gone.

fields.file.url string

Url where the file is available at the Contentful media asset system. This field won't be available until the asset is processed.

fields.file.details Object

Details for the file, depending on file type (example: image size in bytes, etc)

isPublished boolean

checks if the asset is published. A published asset might have unpublished changes (@see {Asset.isUpdated})

isUpdated boolean

Checks if the asset is updated. This means the asset was previously published but has unpublished changes.

isArchived boolean

Checks if asset is archived. This means it's not exposed to the Delivery/Preview APIs.

isDraft boolean

Checks if the asset is in draft mode. This means it is not published.

update function(): Promise<Asset>

Updates an asset

delete function(): Promise<Asset>

Deletes an asset

publish function(): Promise<Asset>

Publishes an asset

unpublish function(): Promise<Asset>

Unpublishes an asset

archive function(): Promise<Asset>

Archives an asset

unarchive function(): Promise<Asset>

Unarchives an asset

processForLocale function(locale: string, options: {processingCheckWait: number, processingCheckRetries: number}): Promise<Asset>

Triggers asset processing after an upload, for the file uploaded to a specific locale.

processForAllLocales function(options: {processingCheckWait: number, processingCheckRetries: number}): Promise<Asset>

Triggers asset processing after an upload, for the files uploaded to all locales of an asset.

toPlainObject function(): Object

Returns this Asset as a plain JS object

Example:


// require contentful-management
var contentfulManagement = require('contentful-management')
var client = contentfulManagement.createClient({
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN'
})

var space = await client.getSpace('SPACE_ID')
var asset = await space.getAsset('ASSET_ID')

// Example Creating an asset
var createdAsset = await space.createAsset(
  fields: {
    file: {
      'en-US': {
         contentType: 'image/jpeg',
         fileName: 'filename_english.jpg',
         upload: 'http://example.com/filename_original_en.jpg'
      },
      'de-DE': {
         contentType: 'image/jpeg',
         fileName: 'filename_german.jpg',
         upload: 'http://example.com/filename_original_de.jpg'
      }
    }
  }
)

// Example Updating an asset
asset.fields.title = 'My new Title'
asset.update()
.then(asset => console.log(asset.fields.name['en-US']))

// Process an asset for a specific locale
asset.processForLocale('en-US')
.then(asset => console.log(asset.fields.file['en-US'].url))

// Process Asset for all locales
asset.processForAllLocales()
.then(asset => console.log(asset.fields.file['en-US'].url, asset.fields.file['de-DE'].url))

// Publish an asset
asset.publish()
.then(asset => console.log(asset.sys.publishedVersion))

// Delete an asset
asset.delete()
.catch(err => console.log(err))

// unPublish an asset
asset.unpublish()
.then(asset => console.log(asset.sys))

// archive an asset
asset.archive()
.then(asset => console.log(asset.sys.archivedVersion))

// unarchive an asset
asset.unarchive()
.then(asset => console.log(asset.sys))

public AssetCollection: AssetCollection source

Properties:

NameTypeAttributeDescription
total number

Total amount of records in the server

skip number

A starting point of the collection

limit number

Amount of records in collection

items Asset[]

an array of assets

toPlainObject function(): Object

Returns this Asset collection as a plain JS object

Example:


// require contentful-management
var contentfulManagement = require('contentful-management')
var client = contentfulManagement.createClient({
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN'
})

let space = await client.getSpace('SPACE_ID')
let assetCollection = await space.getAssets()
console.log("the space contains ", assetCollection.items.length, " assets")
assetCollection.items.forEach((asset) => {
   // do something with asset @link {Asset}
})

public ClientAPI: ClientAPI source

Properties:

NameTypeAttributeDescription
getSpace function(id: string): Promise<Space>

Gets a space with the spcified id

getSpaces function(): Promise<SpaceCollection>

Gets a collection of spaces

createSpace function(data: {name: string}): Promise<Space>

Creates a space

public ContentType: ContentType source

Properties:

NameTypeAttributeDescription
sys Object

System metadata

name string

name of the content type

description string

description of the content type

displayField string

Field used as the main display field for Entries

fields Array<Field>

All the fields contained in this Content Type

isPublished boolean

Checks if the content type is published. A published content type might have unpublished changes (@see {ContentType.isUpdated})

isUpdated boolean

Checks if the content type is updated. This means the content type was previously published but has unpublished changes.

isDraft boolean

Checks if the content type is in draft mode. This means it is not published.

update function(): Promise<ContentType>

Updates a content type in the server

delete function(): Promise<ContentType>

Deletes a content type on the server

publish function(): Promise<ContentType>

Publishes a content type

unpublish function(): Promise<ContentType>

Unpublishes a content type

toPlainObject() function(): Object

Returns this Content Type as a plain JS object

Example:

// require contentful-management
var contentfulManagement = require('contentful-management')
var client = contentfulManagement.createClient({
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN'
})

//=======================================================================================================
// You can get an Entry object by
//
// 1. Creating one
//
// var contentType = await space.createContentType({name: 'Post', fields: []})
//
// OR
//
// 2. Get an existing one
//
// var contentType = await space.getContentType('contentTypeId')
//=======================================================================================================

// Example updating a ContentType
contentType.name = 'New name'
contentType.update()
.then(contentType => console.log(contentType.name))

//Example deleting a content type
contentType.delete()
.catch(err => console.log(err))

public ContentTypeCollection: ContentTypeCollection source

Properties:

NameTypeAttributeDescription
total number

Total amount of records in the server

skip number

A starting point of the collection

limit number

Amount of records in collection

items ContentType[]

An array of contentTypes

toPlainObject function(): Object

Returns this Content Type collection as a plain JS object

Example:


// require contentful-management
var contentfulManagement = require('contentful-management')
var client = contentfulManagement.createClient({
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN'
})

var space = await client.getSpace('SPACE_ID')
//Example getting contentTypes
space.getContentTypes()
 .then(contentTypes => console.log(contentTypes.items))

public ContentfulManagement: ContentfulManagement source

Properties:

NameTypeAttributeDescription
createClient function(params: {accessToken: string, insecure?: boolean, host?: string, hostUpload?: string, agent?: Object, headers?: Object}): ClientAPI

Create a client instance, this is the entry point to the library

Example:

// require contentful-management
var contentfulManagement = require('contentful-management')
var client = contentfulManagement.createClient({
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN'
})

public Control: Control source

Properties:

NameTypeAttributeDescription
widgetId string

defines how the field will look like e.g. singleLine

fieldId string

id of the field that this control is affecting

settings Object

settings for the widget

public EditorInterface: EditorInterface source

Properties:

NameTypeAttributeDescription
sys Object

System metadata

controls Control[]

List of settings per field

update function(): Promise<EditorInterface>

Sends an update to the server with any changes made to the object's properties

getControlForField function(): Control

Gets a control for a specific field

toPlainObject() function(): Object

Returns this Content Type as a plain JS object

Example:


// require contentful-management
var contentfulManagement = require('contentful-management')
var client = contentfulManagement.createClient({
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN'
})

// request our space from Contentful
var space = await client.getSpace('SPACE_ID')

//=======================================================================================================
// web can get an editor interface in two ways
// 1. request our ContentType from Contentful
//
// var contentType = await space.getContentType('CONTENT_TYPE_ID')
//
//1.1 Get the editorInterface through the ContentType
//
// var editorInterface = await contentType.getEditorInterface()
//
// OR
//
// 2. get an editor interface from the Space object right away
//
// var editorInterface = await space.getEditorInterfaceForContentType('CONTENT_TYPE_ID')
//=======================================================================================================

// we'll use option 2

var editorInterface = await space.getEditorInterfaceForContentType('CONTENT_TYPE_ID')

// Example Updating  and editor interface
editorInterface.controls[0] = { "fieldId": "title", "widgetId": "singleLine"}
editorInterface.update()
.then(editorInterface => console.log(editorInterface.controls))

public Entry: Entry source

Properties:

NameTypeAttributeDescription
sys Object

Standard system metadata with additional entry specific properties

sys.contentType Object

Content Type used by this Entry

sys.locale string

If present, indicates the locale which this entry uses

fields Object

Object with content for each field

isPublished boolean

Checks if the entry is published. A published entry might have unpublished changes (@see {Entry.isUpdated})

isUpdated boolean

Checks if the entry is updated. This means the entry was previously published but has unpublished changes.

isDraft boolean

Checks if the entry is in draft mode. This means it is not published.

isArchived boolean

Checks if entry is archived. This means it's not exposed to the Delivery/Preview APIs.

update function(): Promise<Entry>

Updates an entry in the server

delete function(): Promise<Entry>

Deletes an entry on the server

publish function(): Promise<Entry>

Publishes an entry

unpublish function(): Promise<Entry>

Unpublishes an entry

archive function(): Promise<Entry>

Archives an entry

unarchive function(): Promise<Entry>

Unarchives an entry

toPlainObject function(): Object

Returns this Entry as a plain JS object

Example:

// require contentful-management
var contentfulManagement = require('contentful-management')
var client = contentfulManagement.createClient({
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN'
})

//=======================================================================================================
// You can get an Entry object by
//
// 1. Creating one
//
// var entry = await space.createEntry({})
//
// OR
//
// 2. Get an existing one
//
// var entry = await space.getEntry('ENTRY_ID')
//=======================================================================================================

// Example updating an entry
entry.fields.name['en-US'] = 'Blog Post'
entry.update()
.then(entry => console.log(entry.fields.name['en-US']))

// Example deleting an entry
entry.delete()
.catch(err => console.log(err))

// Example publish an entry
entry.publish()
.then(entry => console.log(entry.sys.publishedVersion))

// Example unPublishing an entry
entry.unpublish()
.then(entry => console.log(entry.sys))

// Example archiving an entry
entry.archive()
.then(entry => console.log(entry.sys.archivedVersion))

// Example unarchiving an entry
entry.unarchive()
.then(entry => console.log(entry.sys))

public EntryCollection: EntryCollection source

Properties:

NameTypeAttributeDescription
total number

Total amount of records in the server

skip number

A starting point of the collection

limit number

Amount of records in collection

items Entry[]

array of entries

errors Array<Object>

Array of errors that might occur when retrieving entries.

toPlainObject function(): Object

Returns this Entry collection as a plain JS object

public ErrorResponse: ErrorResponse source

Properties:

NameTypeAttributeDescription
name string

Error name. Usually refers to the sys.id returned on the error server response. If that's not available or is unknown, it defaults to the HTTP error code and status text.

message string

Stringified JSON object with request information, HTTP response details and error details payload (if available). The requestId property is internal to Contentful and it can be used when contacting support about unusual errors.

public Locale: Locale source

Properties:

NameTypeAttributeDescription
sys Object

System metadata

name string
code string

Locale code (example: en-us)

contentDeliveryApi boolean

If the content under this locale should be available on the CDA (for public reading)

contentManagementApi boolean

If the content under this locale should be available on the CMA (for editing)

default boolean

If this is the default locale

optional boolean

If the locale needs to be filled in on entries or not

toPlainObject function(): Object

Returns this Locale as a plain JS object

public LocaleCollection: LocaleCollection source

Properties:

NameTypeAttributeDescription
total number

Total amount of records in the server

skip number

A starting point of the collection

limit number

Amount of records in collection

items Array<Locale>

array of locales

toPlainObject function(): Object

Returns this Locale collection as a plain JS object

public Role: Role source

Properties:

NameTypeAttributeDescription
sys Object

System metadata

name string
permissions Object

Permissions for application sections

policies Object
update function(): Prmise<Role>

Sends an update to the server with any changes made to the object's properties

delete function(): Prmise

Deletes this object on the server.

toPlainObject function(): Object

Returns this Role as a plain JS object

See:

public RoleCollection: RoleCollection source

Properties:

NameTypeAttributeDescription
total number

Total amount of records in the server

skip number

A starting point of the collection

limit number

Amount of records in collection

items Role[]

an array of roles

toPlainObject function(): Object

Returns this Role collection as a plain JS object

public Space: Space source

Properties:

NameTypeAttributeDescription
sys Object

System metadata

sys.id string

Space id

sys.type string

Entity type

name string

Space name

delete function(): Promise

Deletes the space

update function(): Promise<Space>

Updates the space

getContentType function(id: string): Promise<ContentType>

Get a contentType by id

getContentTypes function(): Promise<ContentTypeCollection>

Gets a collection of contentTypes

createContentType function(data: {name: string, fields: Array}): Promise<ContentType>

creates a ContentType

createContentTypeWithId function(id: string, data: {name: string, fields: Array}): Promise<ContentType>

creates a ContentType with a specified id

getEntry function(id: string): Promise<Entry>

Gets an Entry with a custom id

getEntries function(query: Object): Promise<EntryCollection>

Gets a collection of entries

createEntry function(contentTypeId: string, data: {fields: Object}): Promise<Entry>

Creates an Entry

createEntryWithId function(contentTypeId: string, id: string, data: {fields: Object}): Promise<Entry>

Creates an Entry with a specified id

getAsset function(id: string, query: Object): Promise<Asset>

Gets an asset by id

getAssets function(query: Object): Promise<AssetCollection>

Gets a collection of assets

createAsset function(data: {fields: Object}): Promise<Asset>

Creates an asset

createAssetWithId function(id: string, data: {fields: Object}): Promise<Asset>

Creates an asset with the custom id

getLocale function(): Promise<Locale>

Gets a locale

getLocales function(): Promise<LocaleCollection>

Gets a collection of locales

createLocale function(data: {name: string, code: string}): Promise<Locale>

Creates a Locale

getWebhook function(id: string): Promise<webhook>

Gets a webhook

getWebhooks function(): Promise<WebhookCollection>

Gets a collection of webhooks

createWebhook function(data: Object): Promise<Webhook>

Creates a webhook

createWebhookWithId function(id: string, data: Object)

Creates a webhook with a custom id

getRole function(id: string): Promise<Role>

Gets a Role

getRoles function(): Promise<RoleCollection>

Gets a collection of roles

createRole function(data: Object): Promise<Role>

Creates a role

createRoleWithId function(id: string, data: Object): Promise<Role>

Creates a Role with a custom id

getSpaceMembership function(id: string): Promise<SpaceMembership>

Gets a space membership

getSpaceMemberships function(): Promise<SpaceMembershipCollection>

Gets a space memnerships collection

createSpaceMembership function(data: Object): Promise<SpaceMembership>

Creates a space membership

createSpaceMembershipWithId function(id: string, data: Object): Promise<SpaceMembership>

Creates a space membership with a custom id

getApiKey function(id: string): Promise<ApiKey>

Gets an api key

getApiKeys function(): Promise<ApiKeyCollection>

Gets a collection of api keys

createApiKey function(data: Object): Promise<ApiKey>

Creates an api key

createSpaceApi.createApiKeyWithId function(id: string, data: Object): Promise<ApiKey>

Creates an api key with a custom id

toPlainObject function(): Object

Returns this Space as a plain JS object

Example:

// require contentful-management
var contentfulManagement = require('contentful-management')
var client = contentfulManagement.createClient({
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN'
})

//================================================================================================
// To get a space object you have two options:
//
// 1. by creating a new space
//
// var space = await client.createSpace({name: "My new space"})
//
// OR
//
// 2. Get an existing one by id
//
// var space = await client.getSpace('SPACE_ID')
//================================================================================================

// We'll pick option 2.
//
// A space object will be like so
// {
//   "sys": {
//     "type": "Space",
//     "id": "cfexampleapi",
//     "version": 3,
//     "createdAt": "2015-05-18T11:29:46.809Z",
//     "createdBy": {
//       "sys": {
//         "type": "Link",
//         "linkType": "User",
//         "id": "4FLrUHftHW3v2BLi9fzfjU"
//       }
//     },
//     "updatedAt": "2015-05-18T11:29:46.809Z",
//     "updatedBy": {
//       "sys": {
//         "type": "Link",
//         "linkType": "User",
//         "id": "4FLrUHftHW3v2BLi9fzfjU"
//       }
//     }
//   },
//   "name": "Contentful Example API"
// }
var space = await client.getSpace('cfexampleapi')

// Example Deleting a space
space.delete()
.catch(err => console.log(err))

// Example updating a space
space.name = 'Updated Space Name'
space.update()
.then(space => console.log(space.name) // `Updated Space Name`)

// Example getting a contentType
space.getContentType('contentTypeId')
.then(contentType => console.log(contentType)) // @see {ContentType}

// Example getting an editorInterface for a contentType
// an editorInterface is a set of configuration that defines how a field look like
// example singleLine, etc...
space.getEditorInterfaceForContentType('contentTypeId')
.then(editorInterface => console.log(editorInterface))

// Example creating a contentType
space.createContentType({name: 'Post', fields: []})
.then(ct => console.log(ct))

// Example Creating a contentType with a custom id
space.createContentTypeWithId('post', {name: 'Post', fields: []})
.then(ct => console.log(ct))

// Example getting all entries form a space where contentType is `contentTypeId`
// you can add more query params along with the content_type key, like 'limit':'1000', 'order':'sys.createdAt' and more
// for more infos about the query check https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters
space.getEntries({content_type: 'contentTypeId'})
.then(entries => console.log(entries.items))

// Example Creating an entry with a localized title field
// you can fill in all the fields defined in the contentType with the id 'contentTypeId'
// so if you have another field of type text for example called description, you can add 'description' in the fields object
// that will be sent to the server
space.createEntry('contentTypeId', {
  fields: {
    title: {
      'en-US': 'english content',
      'de-DE': 'german content'
    }
  }
})
.then(e => console.log(e))

// Example getting an entry by id
space.getEntry('entryId')
 .then(entity => console.log(entry))

// Example getting assets
space.getAssets()
 .then(response => console.log(response.items))

// Example getting an asset
space.getAsset('assetId')
.then(asset => console.log(asset)) // @see {Asset}

// Example creating an asset
// After creation, call asset.processForLocale or asset.processForAllLocales to start asset processing.
// After processing the upload property name will be replace by 'url'
// if you want to create an asset with a custom id please use the space.createAssetWithId('id', data)
space.createAsset(
  fields: {
    file: {
      'en-US': {
         contentType: 'image/jpeg',
         fileName: 'filename_english.jpg',
         upload: 'http://example.com/filename_original_en.jpg'
      },
      'de-DE': {
         contentType: 'image/jpeg',
         fileName: 'filename_german.jpg',
         upload: 'http://example.com/filename_original_de.jpg'
      }
    }
  }
)
.then(asset => asset.processForAllLocales())

public SpaceCollection: SpaceCollection source

Properties:

NameTypeAttributeDescription
total number

Total amount of records in the server

skip number

A starting point of the collection

limit number

Amount of records in collection

items Array<Space>

An array of spaces

toPlainObject function(): Object

Returns this Space collection as a plain JS object

Example:

// require contentful-management
var contentfulManagement = require('contentful-management')
var client = contentfulManagement.createClient({
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN'
})

client.getSpaces()
  .then((spaceCollection) => {
    console.log(spaceCollection.items) // list of spaces @see {Space}
  })

public SpaceMembership: SpaceMembership source

Properties:

NameTypeAttributeDescription
sys Object

System metadata

name string
admin boolean

User is an admin

roles Array

Array of Role Links

toPlainObject function(): Object

Returns this Space Membership as a plain JS object

public SpaceMembershipCollection: SpaceMembershipCollection source

Properties:

NameTypeAttributeDescription
total number

Total amount of records in the server

skip number

A starting point of the collection

limit number

Amount of records in collection

items Array<SpaceMembership.SpaceMembership>
toPlainObject() function(): Object

Returns this Space Membership collection as a plain JS object

public Upload: Upload source

Properties:

NameTypeAttributeDescription
sys Object

Standard system metadata with additional asset specific properties

sys.id string

The id of the upload

delete function(): Promise

Deletes an upload

toPlainObject function(): Object

Returns this Asset as a plain JS object

Example:


// require contentful-management
var contentfulManagement = require('contentful-management')
var client = contentfulManagement.createClient({
// This is the access token for this space. Normally you get both ID and the token in the Contentful web app
accessToken: 'YOUR_ACCESS_TOKEN'
})

var space = await client.getSpace('SPACE_ID')
const uploadStream = createReadStream('path/to/filename_english.jpg')
space.createUpload(uploadStream)
.then((upload) => {
  // Delete upload again
  return upload.delete()
})
.catch(err => console.log(err))

public Webhook: * source

public WebhookCollection: * source