Contentstack

View as Markdown

Contentstack

The Content Management API (CMA) is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account.

Contentstack

The Content Management API (CMA) is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account.

NameTypeDescription
endpointstring

API endpoint that a service will talk to.

hoststring

API host

Default: api.contentstack.io
headersobject

Optional additional headers

early_accessstring

Optional array of header strings for early access features.

authtokenstring

Optional Authtoken is a read-write token used to make authorized CMA requests, but it is a user-specific token.

authorizationstring

Optional authorization token is a read-write token used to make authorized CMA requests, but it is a user-specific token.

timeoutnumber

Optional number of milliseconds before the request times out.

Default: 30000ms
maxRequestsnumber

Optional maximum number of requests SDK should send concurrently.

Default: 5 concurrent request.
retryOnErrorboolean

Optional boolean for retry on failure.

Default: true
retryLimitnumber

Optional number of retries before failure.

Default: 5
retryDelaynumber

The number of milliseconds to use for operation retries.

Default: 300ms
retryConditionfunction

A function to determine if the error can be retried.

Default: 429
retryDelayOptions.basenumber

The base number of milliseconds to use in the exponential backoff for operation retries.

retryDelayOptions.customBackofffunction

A custom function that accepts a retry count and error and returns the amount of time to delay in milliseconds. (if you want not to retry for specific condition return -1)

maxContentLengthnumber

Optional maximum content length in bytes.

Default: 1073741824 i.e. 1 GB
maxBodyLengthnumber

Optional maximum body length in bytes.

Default: 10 MB
logHandlerfunction

A log handler function to process given log messages & errors.

applicationstring

Application name and version e.g myApp/version

integrationstring

Integration name and version e.g react/version

Client Initialization

import * as contentstack from '@contentstack/management'

const client = contentstack.client();


Set the `endpoint` to 'https://api.contentstack.io:{port}/{version}'

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ endpoint: 'https://api.contentstack.io:{port}/{version}' });


Set the `host` to 'api.contentstack.io'

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ host: 'api.contentstack.io' });


Set the `headers` to { 'headerkey': 'value'}

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ headers: { 'headerkey': 'value'} });


Set the Early Access Headers

import * as contentstack from '@contentstack/management'


const client = contentstack.client({

  early_access: ['early_access_1', 'early_access_2'] 

});


Set the `authtoken`

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authtoken: 'value' });


Set the `authorization`

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ authorization: 'Bearer 

' })


Set the `timeout` to 50000ms

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ timeout: 50000 })


Set the `maxRequests` to 5

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ maxRequests: 5 })


Set the `retryOnError` to false

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ retryOnError: false })


Set the `retryLimit` to 2

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ retryLimit: 2 })

Set the `retryDelay` to 500ms

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ retryDelay: 500 })

Set the `retryCondition` on error status 429

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ retryCondition: (error) => {     if (error.response && error.response.status === 429) {       return true     }     return false   } })

Setbaseretry delay for all services to 300 ms

import * as contentstack from '@contentstack/management'

const client = contentstack.client({retryDelayOptions: {base: 300}})

Set a custom backoff function to provide delay of 500 ms on retryCount < 3 and -1 for retryCount >= 3 values on retries

import * as contentstack from '@contentstack/management'

const client = contentstack.client({retryDelayOptions: {customBackoff: function(retryCount, err) {       if (retryCount < 3) {         return 500       } else {         return -1 //returning -1 will hold next retry for request       }    }}})


Set the `maxContentLength` to 1024 ** 3

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ maxContentLength: 1024 ** 3 })

Set the `maxBodyLength` to 1024 ** 2 * 10 // 10 MB

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ maxBodyLength: 1024 ** 2 * 10 })

Set the `logHandler`

import * as contentstack from '@contentstack/management'

const client = contentstack.client({ logHandler: (level, data) => {

      if (level === 'error' && data) {

        const title = [data.name, data.message].filter((a) => a).join(' - ')

        console.error(`[error] ${title}`)

        return

      }

      console.log(`[${level}] ${data}`)    

} })