Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ClientAPI

Hierarchy

  • ClientAPI

Index

Methods

createPersonalAccessToken

  • 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

    Returns Promise<PersonalAccessToken>

    Promise for a Token

createSpace

  • 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

    • data: SpaceProps

      Object representation of the Space to be created

    • organizationId: string

      Organization ID, if the associated token can manage more than one organization.

    Returns Promise<Space>

    Promise for the newly created Space

getCurrentUser

  • getCurrentUser(): Promise<User>
  • 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<User>

    Promise for a User

getOrganization

  • 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

    • id: string

      Organization ID

    Returns Promise<Organization>

    Promise for a Organization

getOrganizationUsage

  • 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

    • organizationId: string

      Id of an organization

    • query: UsageQuery

      Query parameters

    Returns Promise<Collection<Usage>>

    Promise of a collection of usages

getOrganizations

  • 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<Collection<Organization>>

    Promise for a collection of Organizations

getPersonalAccessToken

  • 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

    Returns Promise<void>

    Promise for a Token

getPersonalAccessTokens

  • 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<Collection<PersonalAccessToken>>

    Promise for a Token

getSpace

  • getSpace(id: string): Promise<Space>
  • 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

    • id: string

      Space ID

    Returns Promise<Space>

    Promise for a Space

getSpaceUsage

  • 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

    • organizationId: string

      Id of an organization

    • query: UsageQuery

      Query parameters

    Returns Promise<Collection<Usage>>

    Promise of a collection of usages

getSpaces

  • getSpaces(params?: undefined | { limit?: undefined | number; skip?: undefined | number }): Promise<Collection<Space>>
  • 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)

    Parameters

    • Optional params: undefined | { limit?: undefined | number; skip?: undefined | number }

    Returns Promise<Collection<Space>>

    Promise for a collection of Spaces

rawRequest

  • rawRequest(Opts: AxiosRequestConfig): Promise<AxiosResponse>
  • 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

    • Opts: AxiosRequestConfig

    Returns Promise<AxiosResponse>

    Promise for the response data