- 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 |
---|---|---|
getOrganization |
function | |
getOrganizations |
function | |
getSpace |
function | |
getSpaces |
function | |
createSpace |
function | |
createPersonalAccessToken |
function | |
getCurrentUser |
function | |
getPersonalAccessTokens |
function | |
getPersonalAccessToken |
function | |
rawRequest |
function | |
getOrganizationUsage |
function | |
getSpaceUsage |
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) getOrganization(id) → {Promise.<Organization.Organization>}
- Source:
Gets an organization
Example
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getOrganization('<org_id>')
.then((org) => console.log(org))
.catch(console.error)
Parameters:
Name | Type | Description |
---|---|---|
id |
string | Organization ID |
Returns:
Promise for a Organization
- Type
- Promise.<Organization.Organization>
(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) getOrganizationUsage(organizationId, query) → {Promise.<Usage.UsageCollection>}
- Source:
Get organization usage grouped by metric
Example
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getOrganizationUsage('<organizationId>', {
'metric[in]': 'cma,gql',
'dateRange.startAt': '2019-10-22',
'dateRange.endAt': '2019-11-10'
}
})
.then(result => console.log(result.items))
.catch(console.error)
Parameters:
Name | Type | Description |
---|---|---|
organizationId |
string | Id of an organization |
query |
Usage.UsageQuery | Query parameters |
Returns:
Promise of a collection of usages
- Type
- Promise.<Usage.UsageCollection>
(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) getSpaceUsage(organizationId, query) → {Promise.<Usage.UsageCollection>}
- Source:
Get organization usage grouped by space and metric
Example
const contentful = require('contentful-management')
const client = contentful.createClient({
accessToken: '<content_management_api_key>'
})
client.getSpaceUsage('<organizationId>', {
skip: 0,
limit: 10,
'metric[in]': 'cda,cpa,gql',
'dateRange.startAt': '2019-10-22',
'dateRange.endAt': '2020-11-30'
}
})
.then(result => console.log(result.items))
.catch(console.error)
Parameters:
Name | Type | Description |
---|---|---|
organizationId |
string | Id of an organization |
query |
Usage.UsageQuery | Query parameters |
Returns:
Promise of a collection of usages
- 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>