ContentfulClientAPI

ContentfulClientAPI

Source:
Contentful Management API Client. Contains methods which allow access to any operations that can be performed with a management token.

Type Definitions

ClientAPI

Source:
Properties:
Name Type Description
getSpace function
getSpaces function
createSpace function
createPersonalAccessToken function
getCurrentUser function
getPersonalAccessTokens function
getPersonalAccessToken function
getOrganizations function
rawRequest function
getUsagePeriods function
getUsages function
Type:
  • Object

Methods

(static) createPersonalAccessToken(data) → {Promise.<User>}

Source:
Creates a personal access token
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.createPersonalAccessToken(
 {
   "name": "My Token",
   "scope": [
     "content_management_manage"
   ]
 }
)
.then(personalAccessToken => console.log(personalAccessToken.token))
.catch(console.error)
Parameters:
Name Type Description
data Object personal access token config
Returns:
Promise for a Token
Type
Promise.<User>

(static) createSpace(data, organizationIdopt) → {Promise.<Space.Space>}

Source:
See:
Creates a space
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.createSpace({
  name: 'Name of new space'
})
.then((space) => console.log(space))
.catch(console.error)
Parameters:
Name Type Attributes Description
data object Object representation of the Space to be created
organizationId string <optional>
Organization ID, if the associated token can manage more than one organization.
Returns:
Promise for the newly created Space
Type
Promise.<Space.Space>

(static) getCurrentUser() → {Promise.<User>}

Source:
Gets the authenticated user
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getCurrentUser()
.then(user => console.log(user.firstName))
.catch(console.error)
Returns:
Promise for a User
Type
Promise.<User>

(static) getOrganizations() → {Promise.<OrganizationCollection>}

Source:
Gets a collection of Organizations
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getOrganizations()
.then(result => console.log(result.items))
.catch(console.error)
Returns:
Promise for a collection of Organizations
Type
Promise.<OrganizationCollection>

(static) getPersonalAccessToken(data) → {Promise.<User>}

Source:
Gets a personal access token
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getPersonalAccessToken(tokenId)
.then(token => console.log(token.token))
.catch(console.error)
Parameters:
Name Type Description
data Object personal access token config
Returns:
Promise for a Token
Type
Promise.<User>

(static) getPersonalAccessTokens() → {Promise.<User>}

Source:
Gets all personal access tokens
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getPersonalAccessTokens()
.then(response => console.log(reponse.items))
.catch(console.error)
Returns:
Promise for a Token
Type
Promise.<User>

(static) getSpace(id) → {Promise.<Space.Space>}

Source:
Gets a space
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpace('<space_id>')
.then((space) => console.log(space))
.catch(console.error)
Parameters:
Name Type Description
id string Space ID
Returns:
Promise for a Space
Type
Promise.<Space.Space>

(static) getSpaces() → {Promise.<Space.SpaceCollection>}

Source:
Gets all spaces
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getSpaces()
.then((response) => console.log(response.items))
.catch(console.error)
Returns:
Promise for a collection of Spaces
Type
Promise.<Space.SpaceCollection>

(static) getUsagePeriods(organizationId) → {Promise.<UsagePeriod.UsagePeriodCollection>}

Source:
Gets a collection of usage periods for the organization.
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getUsagePeriods('<organizationId>')
.then(result => console.log(result.items))
.catch(console.error)
Parameters:
Name Type Description
organizationId string id of organization
Returns:
Promise for a collection of usage periods
Type
Promise.<UsagePeriod.UsagePeriodCollection>

(static) getUsages(organizationId, type, query) → {Promise.<Usage.UsageCollection>}

Source:
Gets a collection of usages for the organization.
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.getUsages('<organizationId>', 'space', {
   'filters[metric]': 'cda', // required
   'filters[usagePeriod]': '1234', // required
   'orderBy[metricUsage]': 'asc'
})
.then(result => console.log(result.items))
.catch(console.error)
Parameters:
Name Type Description
organizationId string
type string either 'organization' or 'space', type of usages to be returned
query Object.<{filters: {metric: string, usagePeriod: string}, orderBy: {metricUsage: string}}> Object with search params. 'filters[metric]' is a required field, possible values are one of 'cda', 'cma', 'cpa', 'all_apis'. 'filters[usagePeriod]' is also required, it's the ID of the usage period. 'orderBy[metricUsage]' is optional, value can be asc or desc. It orders resources in response's 'items' array by total usage
Returns:
Promise for a collection of usage
Type
Promise.<Usage.UsageCollection>

(static) rawRequest(opts) → {Promise.<Object>}

Source:
Make a custom request to the Contentful management API's /spaces endpoint
Example
const contentful = require('contentful-management')

const client = contentful.createClient({
  accessToken: '<content_management_api_key>'
})

client.rawRequest({
  method: 'GET',
  url: '/custom/path'
})
.then((responseData) => console.log(responseData))
.catch(console.error)
Parameters:
Name Type Description
opts Object axios request options (https://github.com/mzabriskie/axios)
Returns:
Promise for the response data
Type
Promise.<Object>