cs-icon.svg

Contentstack - Javascript Management SDK

JavaScript Management SDK for Contentstack

Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. All you have to do is build your application frontend, and Contentstack will take care of the rest.

This SDK uses the Content Management API (CMA). The CMA is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account. To use the CMA, you will need to authenticate your users with a Management Token or an Authtoken. Read more about it in Authentication.

Note: By using CMA, you can execute GET requests for fetching content. However, we strongly recommend that you always use the Content Delivery API to deliver content to your web or mobile properties.

Prerequisite

You need Node.js version 10 or above installed to use the Contentstack JavaScript Management SDK.

Setup and Installation

For Node.js

Install it via npm:

npm i @contentstack/management

To import the SDK, use the following command:

import contentstack from '@contentstack/management'
const contentstackClient = contentstack.client()

Quickstart in 5 mins

Initializing Your SDK

To use the JavaScript CMA SDK, you need to first initialize it. To do this, use the following code:

import contentstack from '@contentstack/management'
const contentstackClient = contentstack.client({ authtoken: 'AUTHTOKEN' })

Authentication

To use this SDK, you need to authenticate your users by using the Authtoken, credentials, or Management Token (stack-level token).

Authtoken

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

import contentstack from '@contentstack/management'
contentstackClient = contentstack.client({ authtoken: 'AUTHTOKEN' })

Login

To Login to Contentstack by using credentials, you can use the following lines of code:

import contentstack from '@contentstack/management'
contentstackClient = contentstack.client()
contentstackClient.login({ email: 'EMAIL', password: 'PASSWORD'})
.then((response) => {
	console.log(response.notice)
	console.log(response.user)
})

Management Token

Management Tokens are stack-level tokens, with no users attached to them.

import contentstack from '@contentstack/management'
contentstackClient = contentstack.client()
contentstackClient.stack({ api_key: 'API_KEY', management_token: 'MANAGEMENT_TOKEN' }).contentType('CONTENT_TYPE_UID')
.fetch()
.then((contenttype) => {
	console.log(contenttype)
})

Fetch Stack Detail

Use the following lines of code to fetch your stack detail using this SDK:

import contentstack from '@contentstack/management'
contentstackClient = contentstack.client({ authtoken: 'AUTHTOKEN' })
contentstackClient.stack({api_key:'API_KEY'})
.fetch()
.then((stack) => {
})

Create Entry

To create an entry in a specific content type of a stack, use the following lines of code:

import contentstack from '@contentstack/management'
var  entry = {
	title:'Sample Entry',
	url:'/sampleEntry'
}
contentstackClient = contentstack.client({ authtoken: 'AUTHTOKEN' })
contentstackClient.stack({ api_key:'API_KEY'})
  .contentType('CONTENT_TYPE_UID')
  .entry()
  .create({ entry })
  .then((entry)=>{
  })

Create Asset

The following lines of code can be used to upload assets to your stack:

import contentstack from '@contentstack/management'
var  asset  = {
    upload: 'path/to/file',
    title: 'Asset Title'
}
const contentstackClient = contentstack.client({ authtoken: 'AUTHTOKEN' })
contentstackClient.stack({ api_key: 'API_KEY' }).asset().create({ asset })
.then((asset) => {
})

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.

Returns:
Type
ContentstackClient
NameTypeDescription

endpoint

string

API endpoint that a service will talk to.

host

string

API host

Default: api.contentstack.io

headers

object

Optional additional headers

early_access

string

Optional array of header strings for early access features.

authtoken

string

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

authorization

string

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

timeout

number

Optional number of milliseconds before the request times out.

Default: 30000ms

maxRequests

number

Optional maximum number of requests SDK should send concurrently.

Default: 5 concurrent request.

retryOnError

boolean

Optional boolean for retry on failure.

Default: true

retryLimit

number

Optional number of retries before failure.

Default: 5

retryDelay

number

The number of milliseconds to use for operation retries.

Default: 300ms

retryCondition

function

A function to determine if the error can be retried.

Default: 429

retryDelayOptions.base

number

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

retryDelayOptions.customBackoff

function

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)

maxContentLength

number

Optional maximum content length in bytes.

Default: 1073741824 i.e. 1 GB

maxBodyLength

number

Optional maximum body length in bytes.

Default: 10 MB

logHandler

function

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

application

string

Application name and version e.g myApp/version

integration

string

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

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 >= 3values 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}`)    
} })

ContentstackClient

login

The login call is used to sign in to your Contentstack account and obtain the authtoken.
Returns:
Type
Promise
NameTypeDescription

email (required)

string

email id for user to login

password (required)

string

password for user to login

token

string

token for user to login

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.login({ email: <emailid>, password: <password> })
.then(() => {
}))

getUser

The Get user call returns comprehensive information of an existing user account. The information returned includes details of the stacks owned by and shared with the specified user account.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.getUser()
.then((user) => {
})

logout

The Log out of your account call is used to sign out the user of Contentstack account.

Returns:
Type
Organization
NameTypeDescription

authtoken

string

Authtoken to logout from.

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.logout()
.then((response) => {
})

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.logout('AUTHTOKEN')
.then((response) => {
})

stack

Get Stack instance. A stack is a space that stores the content of a project.

Returns:
Type
Promise
NameTypeDescription

api_key (required)

string

Stack API Key

management_token

string

Management token for Stack.

branch_uid

string

Branch name or alias to access specific branch.

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
const stack = {name: 'My New Stack'}
client.stack().create({ stack }, { organization_uid: 'org_uid' })
.then((stack) =>{
})

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).fetch()
.then((stack) => {
})

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key', management_token: 'management_token'
})
.contentType('content_type_uid')
.fetch()
.then((stack) => console.log(stack))

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key', management_token: 'management_token', branch_uid: 'branch_uid' })
.contentType('content_type_uid').fetch()
.then((stack) => {
})

organization

Organization is the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources, and users.

Returns:
Type
Organization
NameTypeDescription

uid

string

Organization UID.

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.organization().findAll()
.then((organization) => {
})

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.organization('org_uid').fetch()
.then((organization) => {
})

User

All accounts registered with Contentstack are known as Users. A stack can have many users with varying permissions and roles. Read Users to learn more.

update

The Update User API Request updates the details of an existing user account.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.getUser()
.then((user) => {
   user.first_name = 'FirstName'
   user.last_name = 'LastName'
   user.company = 'company'
   return user.update()  
)}
.then((response) => {
})

delete

The Delete user call deletes the current authenticated user permanently from your Contentstack account.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.getUser()
.then((user) => {
	return requestPassword({ email })
)}
.then((response) => {
})

requestPassword

The Request for a password call sends a request for a temporary password to log in to an account in case a user has forgotten the login password.

Returns:
Type
Promise
NameTypeDescription

param.email (required)

string

Email id for which password request to be sent.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client..getUser()
.then((user) => {
   return requestPassword({ email })
})
.then((response) => {
})

resetPassword

The Reset password call sends a request for resetting the password of your Contentstack account.

Returns:
Type
Promise
NameTypeDescription

param. reset_password_token (required)

string

Reset password token generated from request password

param.password (required)

string

New password to set for your account

param.password_confirmation

string

Confirm password matching your password

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.getUser()
.then((user) => {
    return user.resetPassword({ 'resetToken', 'new_password', 'new_password' })
})
.then((response) => {
})

getTasks

The Get all Tasks request retrieves a list of all tasks assigned to you.

Returns:
Type
Promise
NameTypeDescription

param.query

Object

Enter the actual query that will be executed to retrieve the tasks. This query should be in JSON format.

param.sort

Object

Enter the field UID on the basis of which you want to sort your tasks.

param.limit

number

Enter the maximum number of tasks that you want to retrieve in the response.

param.skip

number

Enter the number of tasks to be skipped.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.getUser()
.then((user) => {
    return user.getTasks()
})
.then((response) => {
})

Organization

Organization is the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources, and users. Organization allows easy management of projects as well as users within the Organization.

fetch

The fetch Organization call fetches Organization details.

Returns:
Type
Promise
NameTypeDescription

param.include_plan

number

The include_plan parameter includes the details of the plan that the organization has subscribed to.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.organization('organization_uid').fetch()
.then((organization) => console.log(organization))

stacks

The Get all stacks in an organization call fetches the list of all stacks in an Organization.

Returns:
Type
Promise
NameTypeDescription

param.limit

number

he ‘limit’ parameter will return a specific number of organizations in the output.

param.skip

number

The ‘skip’ parameter will skip a specific number of organizations in the output.

param.asc

string

The ‘asc’ parameter allows you to sort the list of organizations in the ascending order with respect to the value of a specific field.

desc

string

The ‘desc’ parameter allows you to sort the list of Organizations in the descending order with respect to the value of a specific field.

include_count

boolean

The ‘include_count’ parameter returns the total number of organizations related to the user.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.organization('organization_uid').stacks({ include_count: true })
.then((collection) => console.log(collection))

addUser

The Add users to organization call allows you to send invitations to add users to your organization. Only the owner or the admin of the organization can add users.

Returns:
Type
Promise
NameTypeDescription

param.users

object

List of users to add with roles.

params.stacks

object

List of user with stack API key and roles id to be assign from stack.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.organization('organization_uid').addUser({ users: { 'abc@test.com': ['org_uid1', 'org_uid2' ]}, stacks: { 'abc@test.com': { 'api_key1': [ 'stack_role_id' ] } } })
.then((response) => console.log(response))

transferOwnership

The Transfer organization ownership call transfers the ownership of an Organization to another user.

Returns:
Type
Promise
NameTypeDescription

email (required)

string

Email id of user to transfer the ownership of the organization.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.organization('organization_uid').transferOwnership('email_id')
.then((response) => console.log(response))

getInvitations

The Get all organization invitations call gives you a list of all the Organization invitations.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.organization('organization_uid').getInvitations()
.then((response) => console.log(response))

resendInvitition

The Resend pending organization invitation call allows you to resend Organization invitations to users who have not yet accepted the earlier invitation.

Returns:
Type
Promise
NameTypeDescription

invitation_uid (required)

string

The invitation id for which request to be sent

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.organization('organization_uid').resendInvitition('invitation_uid')
.then((response) => console.log(response.notice))

roles

A role is a collection of permissions that will be applicable to all the users who are assigned this role.
Returns:
Type
Promise
NameTypeDescription

param.limit

number

he ‘limit’ parameter will return a specific number of organizations in the output.

param.skip

number

The ‘skip’ parameter will skip a specific number of organizations in the output.

param.asc

string

The ‘asc’ parameter allows you to sort the list of organizations in the ascending order with respect to the value of a specific field.

desc

string

The ‘desc’ parameter allows you to sort the list of Organizations in the descending order with respect to the value of a specific field.

include_count

boolean

The ‘include_count’ parameter returns the total number of organizations related to the user.

include_stack_roles

boolean

The Include stack roles will return stack details in roles.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.organization('organization_uid').roles()
.then((roles) => console.log(roles))

fetchAll

The Get all organizations call lists all organizations related to the system user in the order that they were created.

Returns:
Type
Promise
NameTypeDescription

param.limit

number

he ‘limit’ parameter will return a specific number of organizations in the output.

param.skip

number

The ‘skip’ parameter will skip a specific number of organizations in the output.

param.asc

string

The ‘asc’ parameter allows you to sort the list of organizations in the ascending order with respect to the value of a specific field.

desc

string

The ‘desc’ parameter allows you to sort the list of Organizations in the descending order with respect to the value of a specific field.

include_count

boolean

The ‘include_count’ parameter returns the total number of organizations related to the user.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.organization().fetchAll()
.then((collection) => console.log(collection))

organization

Organization is the top-level entity in the hierarchy of Contentstack, consisting of stacks and stack resources, and users.

Returns:
Type
Organization
NameTypeDescription

uid

string

Organization UID.

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.organization().findAll()
.then((organization) => {
})

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.organization('org_uid').fetch()
.then((organization) => {
})

Stack

A stack is a space that stores the content of a project (a web or mobile property). Within a stack, you can create content structures, content entries, users, etc. related to the project.

update

The Update stack call lets you update the name and description of an existing stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).fetch()
.then((stack) => {
 stack.name = 'My New Stack'
 stack.description = 'My new test stack'
 return stack.update()
})
.then((stack) => console.log(stack))

fetch

The fetch stack call fetches stack details.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).fetch()
.then((stack) => console.log(stack))

contentType

Content type defines the structure or schema of a page or a section of your web or mobile property.

Returns:
Type
ContentType
NameTypeDescription

uid

string

Uid for content type to perform opertation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType()
// OR
client.stack({ api_key: 'api_key'}).contentType('uid')

locale

Locale allows you to create and publish entries in any language.

Returns:
Type
Locale
NameTypeDescription

uid

string

Uid for locale to perform opertation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).locale()
// OR
client.stack({ api_key: 'api_key'}).locale('uid')

asset

Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use.

Returns:
Type
Asset
NameTypeDescription

uid

string

Uid for asset to perform opertation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset()
// OR
client.stack({ api_key: 'api_key'}).asset('uid')

globalField

Global field defines the structure or schema of a page or a section of your web or mobile property.

Returns:
Type
GlobalField
NameTypeDescription

uid

string

Uid for GlobalField to perform opertation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).globalField()
// OR
client.stack({ api_key: 'api_key'}).globalField('uid')

environment

Environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published.

Returns:
Type
Environment
NameTypeDescription

uid

string

Uid for environment to perform opertation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).environment()
// OR
client.stack({ api_key: 'api_key'}).environment('uid')

branch

Branch corresponds to Stack branch.
Returns:
Type
Branch
NameTypeDescription

uid

string

Uid for branch alias to perform opertation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).branch()
// OR
client.stack({ api_key: 'api_key'}).branch('uid')

branchAlias

Delivery Tokens provide read-only access to the associated environments.

Returns:
Type
BranchAlias
NameTypeDescription

uid

string

Uid for branch alias to perform opertation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).branchAlias()
// OR
client.stack({ api_key: 'api_key'}).branchAlias('uid')

deliveryToken

Delivery Tokens provide read-only access to the associated environments.

Returns:
Type
DeliveryToken
NameTypeDescription

uid

string

Uid for delivery token to perform opertation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).deliveryToken()
// OR
client.stack({ api_key: 'api_key'}).deliveryToken('uid')

extension

Extensions let you create custom fields and custom widgets that lets you customize Contentstack's default UI and behaviour.

Returns:
Type
Extension
NameTypeDescription

uid

string

Uid for extension to perform opertation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).extension()
// OR
client.stack({ api_key: 'api_key'}).extension('uid')

workflow

Workflow is a tool that allows you to streamline the process of content creation and publishing, and lets you manage the content lifecycle of your project smoothly.
Returns:
Type
workflow
NameTypeDescription

uid

string

Uid for workflow to perform opertation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).workflow()
// OR
client.stack({ api_key: 'api_key'}).workflow('uid')

webhook

Webhooks allow you to specify a URL to which you would like Contentstack to post data when an event happens.

Returns:
Type
Webhook
NameTypeDescription

uid

string

Uid for webhook to perform opertation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).webhook()
// OR
client.stack({ api_key: 'api_key'}).webhook('uid')

label

Labels allow you to group a collection of content within a stack. Using labels you can group content types that need to work together

Returns:
Type
Label
NameTypeDescription

uid

string

Uid for label to perform opertation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).label()
// OR
client.stack({ api_key: 'api_key'}).label('label_uid')

release

You can pin a set of entries and assets (along with the deploy action, i.e., publish/unpublish) to a ‘release’, and then deploy this release to an environment.

Returns:
Type
Release
NameTypeDescription

uid

string

Uid for release to perform operation on.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).release()
// OR
client.stack({ api_key: 'api_key'}).release('release_uid')

bulkOperation

Bulk operations such as Publish, Unpublish, and Delete on multiple entries or assets.

Returns:
Type
BulkOperation
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).bulkOperation()

users

The Get all users of a stack call fetches the list of all users of a particular stack

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const users = {
 user_uid: ['role_uid_1', 'role_uid_2' ]
}
client.stack({ api_key: 'api_key'}).users()
.then((users) => console.log(users))

updateUsersRoles

The Update User Role API Request updates the roles of an existing user account. This API Request will override the existing roles assigned to a user.

Returns:
Type
Promise
NameTypeDescription

users (required)

object

User object with userid and roles to assign to them.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const users = {
 user_uid: ['role_uid_1', 'role_uid_2' ]
}
client.stack({ api_key: 'api_key'}).updateUsersRoles(users)
.then((response) => console.log(response.notice))

transferOwnership

The Transfer stack ownership to other users call sends the specified user an email invitation for accepting the ownership of a particular stack.

Returns:
Type
Promise
NameTypeDescription

email (required)

string

The email address of the user to whom you wish to transfer the ownership of the stack.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack().client.stack({ api_key: 'api_key'}).transferOwnership('emailId')
.then((response) => console.log(response.notice))

settings

The Get stack settings call retrieves the configuration settings of an existing stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack().client.stack({ api_key: 'api_key'}).settings()
.then((settings) => console.log(settings))

resetSettings

The Reset stack settings call resets your stack to default settings, and additionally, lets you add parameters to or modify the settings of an existing stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack().client.stack({ api_key: 'api_key'}).resetSettings()
.then((settings) => console.log(settings))

addSettings

The Add stack settings call lets you add settings for an existing stack.

Returns:
Type
Promise
NameTypeDescription

param (required)

object

Object for adding to the stack settings

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack().client.stack({ api_key: 'api_key'}).addSettings({ key: 'value' })
.then((settings) => console.log(settings))

share

The Share a stack call shares a stack with the specified user to collaborate on the stack.

Returns:
Type
Promise
NameTypeDescription

email (required)

Array<string>

Email id to unshare stack.

roles (required)

Array<object>

Email and role to assign to the user.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack().client.stack({ api_key: 'api_key'}).share([ "manager@example.com" ], { "manager@example.com": [ "abcdefhgi1234567890" ] })
.then((response) => console.log(response.notice))

unShare

The Unshare a stack call unshares a stack with a user and removes the user account from the list of collaborators.

Returns:
Type
Promise
NameTypeDescription

email (required)

string

Email id to unshare stack.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack().client.stack({ api_key: 'api_key'}).unShare('email@id.com')
.then((response) => console.log(response.notice))

role

A role is a collection of permissions that will be applicable to all the users who are assigned this role.

Returns:
Type
Role
NameTypeDescription

role_uid

string

Role uid for initiating role class

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack().client.stack({ api_key: 'api_key'}).role()
//or

create

The Create stack call creates a new stack in your Contentstack account.

Returns:
Type
Promise
NameTypeDescription

params.stack.name (required)

string

Name for the stack

params.stack.master_locale (required)

string

Master locale for the Stack.

param.stack.description

Description for the Stack.

params.organization_uid

string

Organization uid to create stack within the organization.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const newStack = {
    stack:
        {
          name: 'My New Stack',
          description: 'My new test stack',
          master_locale: 'en-us'
        }
}
client.stack().create(newStack, { organization_uid: 'org_uid' })
.then((stack) => console.log(stack))

query

The Query on Stack will allow to fetch details of all or specific Stack.

Returns:
Type
Query
NameTypeDescription

params.include_collaborators

boolean

Set this parameter to 'true' to include the details of the stack collaborators.

params.include_stack_variablesSet

boolean

This to 'true' to display the stack variables. Stack variables are extra information about the stack, such as the description, format of date, format of time, and so on. Users can include or exclude stack variables in the response.

params.include_discrete_variables

boolean

Set this to 'true' to view the access token of your stack.

params.include_count

boolean

Set this to 'true' to include in the response the total count of the stacks owned by or shared with a user account.

params.query

object

Queries that you can use to fetch filtered results.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack().query({ query: { name: 'Stack Name' } }).find()
.then((stack) => console.log(stack))

auditlog

Audit log displays a record of all the activities performed in a stack and helps you keep a track of all published items, updates, deletes, and current status of the existing content.

Returns:
Type
AuditLog
NameTypeDescription

logItemUid (required)

String

UID of the log item

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).auditLog().fetchAll()
.then((logs) => console.log(logs))
client.stack({ api_key: 'api_key' }).auditLog('log_item_uid').fetch()
.then((log) => console.log(log))

ContentType

Content type defines the structure or schema of a page or a section of your web or mobile property. To create content for your application, you are required to first create a content type, and then create entries using the content type.

update

The Update ContentType call lets you update the name and description of an existing ContentType. You can also update the JSON schema of a content type, including fields and different features associated with the content type.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').fetch()
.then((contentType) => {
 contentType.title = 'My New Content Type'
 contentType.description = 'Content Type description'
 return contentType.update()
})
.then((contentType) => console.log(contentType))

delete

The Delete ContentType call is used to delete an existing ContentType permanently from your Stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').delete()
.then((response) => console.log(response.notice))

fetch

The fetch ContentType call fetches ContentType details.

Returns:
Type
Promise
NameTypeDescription

version

number

Version number to fetch specific version of ContentType.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').fetch()
.then((contentType) => console.log(contentType))

entry

Content type defines the structure or schema of a page or a section of your web or mobile property.

Returns:
Type
Entry
NameTypeDescription

uid

string

Entry uid to perform operation on

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry()
//OR
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('entry_uid')

generateUid

Generate uid from the title of content type

Returns:
Type
string
NameTypeDescription

title (required)

string

Title for which ContentType uid needs to be generated.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType().generateUid('name')

create

The Create a content type call creates a new content type in a particular stack of your Contentstack account.
Returns:
Type
Promise
NameTypeDescription

params.content_type (required)

object

ContentType details and schema to create.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const content_type = {name: 'My New contentType'}
client.stack({ api_key: 'api_key'}).contentType().create({ content_type })
.then((contentType) => console.log(contentType))

query

The Query on Content Type will allow to fetch details of all or specific Content Type

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType().query({ query: { name: 'Content Type Name' } }).find()
.then((contentTypes) => console.log(contentTypes))

import

The Import a content type call imports a content type into a stack.

Returns:
Type
Promise
NameTypeDescription

params.content_type (required)

string

File path to import content type

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const data = {
 content_type: 'path/to/file.json',
}
client.stack({ api_key: 'api_key'}).contentType().import(data)
.then((contentType) => console.log(contentType))

GlobalField

GlobalField defines the structure or schema of a page or a section of your web or mobile property. To create global Fields for your application, you are required to first create a global field.

update

The Update GlobalField call lets you update the name and description of an existing GlobalField.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).globalField('global_field_uid').fetch()
.then((globalField) => {
 globalField.title = 'My New global field'
 globalField.description = 'global field description'
 return globalField.update()
})
.then((globalField) => console.log(globalField))

delete

The Delete GlobalField call is used to delete an existing GlobalField permanently from your Stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).globalField('global_field_uid').delete()
.then((response) => console.log(response.notice))

fetch

The fetch GlobalField call fetches GlobalField details.

Returns:
Type
Promise
NameTypeDescription

version

number

Version number to fetch specific version of GlobalField.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).globalField('global_field_uid').fetch()
.then((globalField) => console.log(globalField))

create

The Create a GlobalField call creates a new globalField in a particular stack of your Contentstack account.

Returns:
Type
Promise
NameTypeDescription

params.global_field (required)

object

GlobalField details and schema to create.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const global_field = {name: 'My New global field'}
client.stack({ api_key: 'api_key'}).globalField().create({ global_field })
.then((globalField) => console.log(globalField))

query

The Query on GlobalField will allow to fetch details of all or specific GlobalField

Returns:
Type
Query
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).globalField().query({ query: { name: 'Global Field Name' } }).find()
.then((globalField) => console.log(globalField))

import

The Import a global field call imports a global field into a stack.

Returns:
Type
Promise
NameTypeDescription

params.global_field (required)

string

File path to import GlobalField

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const data = {
 global_field: 'path/to/file.json',
}
client.stack({ api_key: 'api_key'}).globalField().import(data)
.then((globalField) => console.log(globalField))

Entry

An entry is the actual piece of content created using one of the defined content types. Read more about Entries.

update

The update an entry call updates an entry of a selected content type.

Returns:
Type
Promise

Here's how you can update an entry:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')
.fetch()
.then((entry) => {
 entry.title = 'My New Entry'
 entry.description = 'Entry description'
 return entry.update()
})
.then((entry) => console.log(entry))

Here's how you can update an entry in a specific locale:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')
.fetch()
.then((entry) => {
 entry.title = 'My New Entry'
 entry.description = 'Entry description'
 return entry.update({ locale: 'en-at' })
})
.then((entry) => console.log(entry))

Here's how you can update an entry with multiple assets:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')
.fetch()
.then((entry) => {
 entry.title = 'My New Entry'
 entry.file = entry.file.uid // for single asset pass asset uid to entry asset field value
 entry.multiple_file = ['asset_uid_1', 'asset_uid_2'] // for multiple asset pass array of asset uid to entry asset
field values
 return entry.update({ locale: 'en-at' })
})
.then((entry) => console.log(entry))

Here's how you can update an entry with referenced entries:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')
.fetch()
.then((entry) => {
 entry.title = 'My New Entry'
 entry.reference = entry.reference.uid // for single reference pass reference uid to entry reference field value
 entry.multiple_reference = ['reference_uid_1', 'reference_uid_2'] // for multiple reference pass array of
reference uid to entry reference field values
 entry.multiple_content_type_reference = [{_content_type_uid: 'content_type_uid_1', uid: 'reference_uid_1'},
{_content_type_uid: 'content_type_uid_2', uid: 'reference_uid_2'}] // for multiple reference pass array of
reference uid to entry reference field values
 return entry.update({ locale: 'en-at' })
})
.then((entry) => console.log(entry))

delete

The Delete an entry call is used to delete a specific entry from a content type.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')
.delete()
.then((response) => console.log(response.notice))

fetch

The fetch Entry call fetches Entry details.
Returns:
Type
Promise
NameTypeDescription

params.version

number

Enter the version number of the entry that you want to retrieve. However, to retrieve a specific version of an entry, you need to keep the environment parameter blank.

params.locale

string

Enter the code of the language of which the entries need to be included. Only the entries published in this locale will be displayed.

params.include_workflow (required)

boolean

Enter 'true' to include the workflow details of the entry.

params.include_publish_details

string

Enter 'true' to include the publish details of the entry.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')
.fetch()
.then((entry) => console.log(entry))

publish

The publish call is used to publish a specific version of an entry on the desired environment either immediately or at a later date/time.

Returns:
Type
Promise
NameTypeDescription

params.publishing_detalis (required)

object

Details of entry to be publish.

params.locale

string

Enter the code of the locale that the entry belongs to.

params.version

number

Entry version to be publish

params.scheduledAt

string

Schedule date for publishing entry.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const entry = {
 "locales": [
             "en-us"
             ],
  "environments": [
               "development"
              ]
}
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')
.publish({ publishDetails: entry, locale: "en-us", version: 1, scheduledAt: "2019-02-08T18:30:00.000Z"})
.then((response) => console.log(response.notice))

unpublish

The unpublish call is used to unpublish a specific version of an entry on the desired environment either immediately or at a later date/time.

Returns:
Type
Promise
NameTypeDescription

params.publishing_detalis (required)

object

Details of entry to be publish.

params.locale

string

Enter the code of the locale that the entry belongs to.

params.version

number

Entry version to be publish

params.scheduledAt

string

Schedule date for publishing entry.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const entry = {
 "locales": [
             "en-us"
             ],
  "environments": [
               "development"
              ]
}
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')
.unpublish({ publishDetails: entry, locale: "en-us", version: 1, scheduledAt: "2019-02-08T18:30:00.000Z"})
.then((response) => console.log(response.notice))

publishRequest

This multipurpose request allows you to either send a publish request or accept/reject a received publish request.

Returns:
Type
Promise
NameTypeDescription

params.publishing_rule (required)

object

Details for the publish request

locale

string

Enter the code of the locale that the entry belongs to.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const publishing_rule = {
"uid": "uid",
"action": "publish" 
"status": 1,
"notify": false,
comment": "Please review this."
}
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')
.publishRequest({ publishing_rule, locale: 'en-us'})
.then((response) => console.log(response.notice))

setWorkflowStage

The Set Entry Workflow Stage request allows you to either set a particular workflow stage of an entry or update the workflow stage details of an entry.

Returns:
Type
Promise
NameTypeDescription

params.publishing_rule (required)

object

Details for the publish request

locale

string

Enter the code of the locale that the entry belongs to.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const workflow_stage = {
   "comment": "Workflow Comment",
   "due_date": "Thu Dec 01 2018",
   "notify": false,
   "uid": "workflow_stage_uid",
   "assigned_to": [{
     "uid": "user_uid",
     "name": "Username",
     "email": "user_email_id"
     }],
   "assigned_by_roles": [{
   "uid": "role_uid",
   "name": "Role name"
 }]
}
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry('uid')
.setWorkflowStage({workflow_stage, locale: 'en-us'})
.then((response) => console.log(response.notice));

create

The Create an entry call creates a new entry in a particular stack of your Contentstack account.

Returns:
Type
Promise
NameTypeDescription

params.entry (required)

object

Entry details to create.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const entry  = {
 title: 'Sample Entry',
 url: '/sampleEntry',
 file = asset_uid, /
 multiple_file = ['asset_uid_1', 'asset_uid_2'], 
 reference: reference.uid, 
multiple_reference: ['reference_uid_1', 'reference_uid_2'], 
 multiple_content_type_reference: [{_content_type_uid: 'content_type_uid_1', uid: 'reference_uid_1'},
{_content_type_uid: 'content_type_uid_2', uid: 'reference_uid_2'}] 
}
client.stack().contentType('content_type_uid').entry().create({ entry })
.then((entry) => console.log(entry))

query

The Query on Entry will allow to fetch details of all or specific Entry

Returns:
Type
Promise
NameTypeDescription

params.locale

string

Enter the code of the language of which the entries need to be included. Only the entries published in this locale will be displayed.

params.include_workflow

boolean

Enter 'true' to include the workflow details of the entry.

params.include_publish_details

boolean

Enter 'true' to include the publish details of the entry.

params.query

object

Queries that you can use to fetch filtered results.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry().query({ query: { title: 'entry title' } }).find()
.then((entry) => console.log(entry))

import

The Import an entry call imports an entry into a stack.

Returns:
Type
Promise
NameTypeDescription

params.entry (required)

string

File path to import Entry

locale

string

Enter the code of the language to import the entry of that particular language.

overwrite

boolean

Select 'true' to replace an existing entry with the imported entry file.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const data = {
 entry: 'path/to/file.json',
}
client.stack({ api_key: 'api_key'}).contentType('content_type_uid').entry().import(data)
.then((entry) => console.log(entry))

Asset

Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use. These files can be attached and used in multiple entries.

update

The Update Asset call lets you update the name and description of an existing Asset.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset('uid')
.fetch()
.then((asset) => {
 asset.title = 'My New asset'
 asset.description = 'Asset description'
 return asset.update()
})
.then((asset) => console.log(asset))

delete

The Delete asset call will delete an existing asset from the stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset('uid')
.delete()
.then((response) => console.log(response.notice))

fetch

The fetch an asset call returns comprehensive information about a specific version of an asset of a stack.
Returns:
Type
Promise
NameTypeDescription

params.version

number

Enter the version number of the asset that you want to retrieve. However, to retrieve a specific version of an entry, you need to keep the environment parameter blank.

params.include_publish_details

string

Enter 'true' to include the publish details of the entry.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset('uid')
.fetch()
.then((asset) => console.log(asset))

replace

The Replace asset call will replace an existing asset with another file on the stack.

Returns:
Type
Promise
NameTypeDescription

params.asset (required)

object

Asset details to replace.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const asset = {
 upload: 'path/to/file.png',
 title: 'Title',
 description: 'Desc'
}
client.stack({ api_key: 'api_key'}).asset('uid').replace(asset)
.then((asset) => console.log(asset))

unpublish

The publish call is used to publish a specific version of an asset on the desired environment either immediately or at a later date/time.

Returns:
Type
Promise
NameTypeDescription

params.publishing_detalis (required)

object

Details of asset to be publish.

params.locale

string

Enter the code of the locale that the entry belongs to.

params.version

number

Asset version to be publish

params.scheduledAt

string

Schedule date for publishing Asset.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const asset = {
 "locales": [
             "en-us"
             ],
  "environments": [
               "development"
              ]
}
client.stack({ api_key: 'api_key'}).asset('uid')
.publish({ publishDetails: asset, locale: "en-us", version: 1, scheduledAt: "2019-02-08T18:30:00.000Z"})
.then((response) => console.log(response.notice))

unpublish

The unpublish call is used to unpublish a specific version of an asset on the desired environment either immediately or at a later date/time.

Returns:
Type
Promise
NameTypeDescription

params.publishing_detalis (required)

object

Details of asset to be publish.

params.locale

string

Enter the code of the locale that the entry belongs to.

params.version

number

Asset version to be publish

params.scheduledAt

string

Schedule date for publishing Asset.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const asset = {
 "locales": [
             "en-us"
             ],
  "environments": [
               "development"
              ]
}
client.stack({ api_key: 'api_key'}).asset('uid')
.unpublish({ publishDetails: asset, locale: "en-us", version: 1, scheduledAt: "2019-02-08T18:30:00.000Z"})
.then((response) => console.log(response.notice))

folder

The Folder allows to fetch and create folders in assets.

Returns:
Type
Promise
NameTypeDescription

uid

string

Folder uid to perform operation

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset('uid').folder()
//OR

create

The Create an asset call creates a new asset.

Returns:
Type
Promise
NameTypeDescription

params.asset (required)

object

Asset details to create.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const asset = {
 upload: 'path/to/file.png',
 title: 'Title',
 description: 'Desc'
}
client.stack({ api_key: 'api_key'}).asset().create(asset)
.then((asset) => console.log(asset))

query

The Query on Asset will allow to fetch details of all or specific Asset.

Returns:
Type
Promise
NameTypeDescription

params.include_publish_details

boolean

Enter 'true' to include the publish details of the entry.

params.query

object

Queries that you can use to fetch filtered results.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset()
.query({ query: { filename: 'Asset Name' } })
.find()
.then((asset) => console.log(asset))

download

The Download function will get downloadable file in specified format.

Returns:
Type
Promise
NameTypeDescription

param.url

string

The url for the asset to download

param.responseType

string

Optional parameter to specify the response type.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset('uid')
.fetch()
.then((asset) => asset.download({responseType: 'blob'}))
.then((response) => // Write response data to destination file. )

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset()
.download({url: 'asset_url_to_download', responseType: 'blob'})
.then((response) => // Write response data to destination file. )

Branch

Branches efficiently present independent workspaces where developers and content managers can work parallely on content models and content. It helps sync the development activities of websites.

delete

The Delete Branch call is used to delete an existing Branch permanently from your Stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).branch('uid')
.delete()
.then((response) => console.log(response.notice))

fetch

The fetch Branch call fetches Branch details.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).branch('uid')
.fetch()
.then((branch) => console.log(branch))

create

The Create a Branch call creates a new branch in a particular stack of your Contentstack account.

Returns:
Type
Promise
NameTypeDescription

params.branch (required)

object

Branch details to create.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const branch = {
     name: 'branch_name',
     source: 'master'
}
client.stack().branch().create({ branch })
.then((branch) => console.log(branch))

query

The 'Get all Branch' request returns comprehensive information about branch created in a Stack.

Returns:
Type
Promise
NameTypeDescription

params.include_publish_details

boolean

Enter 'true' to include the publish details of the entry.

params.query

object

Queries that you can use to fetch filtered results.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).branch()
.query()
.find()
.then((branch) => console.log(branch))

compare all

The all call is used to compare the differences between all the content types and global fields of two branches.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'})
    .branch('branch_uid')
    .compare('compare_branch_uid')
    .all({skip: 0, limit: 100})
    .then(response => console.log(response))

compare contentType

The contentType call is used to compare the differences only between the content types of two branches.

You can specify the content type UID to fetch the difference of a specific content type. If no UID is specified, differences for all content types are fetched in a paged way.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const compare = client.stack({ api_key: 'API_KEY' }).branch(_base_branch_uid).compare(_compare_branch_uid)
compare.contentType({
  uid?: UID, skip?: 4, limit?: 20, include_schemas?: true
})
.then(response)
.catch(error)

compare globalField

The globalField call is used to compare the differences only between the global fields of two branches.

You can specify the global field UID to fetch the difference of a specific global field. If no UID is specified, differences for all global fields are fetched in a paged way.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const compare = client.stack({ api_key: 'API_KEY' }).branch(_base_branch_uid).compare(_compare_branch_uid)
compare.globalField({
  uid?: UID, skip?: 4, limit?: 20, include_schemas?: true
})
.then(response)
.catch(error)

merge

The merge call is used to merge two branches. You can choose to use a default merge strategy for all content types and global fields, or you can opt for specific merge strategies for particular content types or global fields.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const branch = contentstack.client({ authtoken }).stack({ api_key: 'api_key'}).branch()
branch.merge({
  base_branch: "main",
  compare_branch: "dev",
  default_merge_strategy: "merge_prefer_base",
  item_merge_strategies: [ 
    {
      uid: "global_field_uid", 
      type: "global_field", 
      merge_strategy: "merge_prefer_base"
    }
  ],
  merge_comment: "Merging dev into main", 
  no_revert: true
})

fetch mergeQueue

The fetch mergeQueue call is used to fetch a specific merge job in a specific branch.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const branch = contentstack.client.stack({ api_key: 'API_KEY' }).branch('branch_uid')
branch.mergeQueue( 'UID')
.fetch()
.then(response)
.catch(error)

find mergeQueue

The find mergeQueue call is used to fetch all merge jobs in a specific branch.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const branch = contentstack.client.stack({ api_key: 'API_KEY' }).branch(branch_uid)
branch.mergeQueue()
.find()
.then(response)
.catch(error)

BranchAlias

Branches efficiently present independent workspaces where developers and content managers can work parallely on content models and content. It helps sync the development activities of websites.

createOrUpdate

The Create or Update BranchAlias call lets you update the name of an existing BranchAlias.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'})
.branchAlias('branch_alias_id')
.createOrUpdate('branch_uid')
.then((branch) => {
 branch.name = 'new_branch_name'
 return branch.update()
})
.then((branch) => console.log(branch))

delete

The Delete BranchAlias call is used to delete an existing BranchAlias permanently from your Stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).branchAlias('uid')
.delete()
.then((response) => console.log(response.notice))

fetch

The fetch BranchAlias call fetches BranchAlias details.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).branchAlias('branch_alias_id')
.fetch()
.then((branch) => console.log(branch))

fetchAll

The Get all BranchAlias request retrieves the details of all the Branch of a stack.

Returns:
Type
Promise
NameTypeDescription

params.limit

number

The limit parameter will return a specific number of Branch in the output.

params.skip

number

The skip parameter will skip a specific number of Branch in the output.

params.include_count

boolean

To retrieve the count of Branch.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).branchAlias()
.fetchAll()
.then((collection) => console.log(collection))

Folder

Folders refer to Asset Folders.

update

The Update Folder call lets you update the name and description of an existing Folder.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset().folder('uid')
.fetch()
.then((folder) => {
 folder.name = 'My New folder'
 return folder.update()
})
.then((folder) => console.log(folder))

delete

The Delete folder call will delete an existing folder from the stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'})asset()
.folder('uid')
.delete()
.then((response) => console.log(response.notice))

fetch

The fetch a folder call returns comprehensive information about folder of a stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset()
.folder('uid')
.fetch()
.then((folder) => console.log(folder))

create

The Create a Folder call creates a folder into the assets.

Returns:
Type
Promise
NameTypeDescription

params.asset (required)

object

Folder details to create.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const asset = {name: 'My New contentType'}
client.stack().asset().folder().create({ asset })
.then((folder) => console.log(folder))

BulkOperation

Bulk operations such as Publish, Un-publish, and Delete on multiple entries or assets.

publish

The Publish entries and assets in bulk request allows you to publish multiple entries and assets at the same time.

Returns:
Type
Promise
NameTypeDescription

params.details

object

Set this with details containing 'entries', 'assets', 'locales', and 'environments' to which you want to publish the entries or assets. If you do not specify a source locale, the entries or assets will be published in the master locale automatically.

params.skip_workflow_stage_check

boolean

Set this to 'true' to publish the entries that are at a workflow stage where they satisfy the applied publish rules.

params.approvals

boolean

Set this to 'true' to publish the entries that do not require an approval to be published.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const publishDetails = {
  entries: [
    {
      uid: '{{entry_uid}}',
      content_type: '{{content_type_uid}}',
      version: '{{version}}',
      locale: '{{entry_locale}}'
    }
  ],
  assets: [{
    uid: '{{uid}}'
  }],
  locales: [
    'en'
  ],
  environments: [
    '{{env_uid}}'
  ]
}
client.stack({ api_key: 'api_key'}).bulkOperation().publish({ details:  publishDetails })
.then((response) => {  console.log(response.notice) })

// For Nested bulk publish pass api_version param with value 3.2
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const publishDetails = {
  environments:["{{env_uid}}","{{env_uid}}"],
  locales:["en-us"],
  entries:[
    {
      _content_type_uid: '{{content_type_uid}}',
      uid: '{{entry_uid}}'
    },
    {
      _content_type_uid: '{{content_type_uid}}',
      uid: '{{entry_uid}}'
    },
    {
      _content_type_uid: '{{content_type_uid}}',
      uid: '{{entry_uid}}'
    }
  ]
}
client
  .stack({ api_key: 'api_key'})
  .bulkOperation().publish({ 
     details:  publishDetails, 
     api_version: 3.2 
  })
  .then((response) => {  console.log(response.notice) })

unpublish

The Unpublish entries and assets in bulk request allows you to unpublish multiple entries and assets at the same time.

Returns:
Type
Promise
NameTypeDescription

params.details

object

Set this with details containing 'entries', 'assets', 'locales', and 'environments' to which you want to unpublish the entries or assets. If you do not specify a source locale, the entries or assets will be unpublished in the master locale automatically.

params.skip_workflow_stage_check

boolean

Set this to 'true' to un-publish the entries that are at a workflow stage where they satisfy the applied un-publish rules.

params.approvals

boolean

Set this to 'true' to un-publish the entries that do not require an approval to be published.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const publishDetails = {
  entries: [
    {
      uid: '{{entry_uid}}',
      content_type: '{{content_type_uid}}',
      version: '{{version}}',
      locale: '{{entry_locale}}'
    }
  ],
  assets: [{
    uid: '{{uid}}'
  }],
  locales: [
    'en'
  ],
  environments: [
    '{{env_uid}}'
  ]
}
client.stack({ api_key: 'api_key'}).bulkOperation().unpublish({ details:  publishDetails })
.then((response) => {  console.log(response.notice) })

// Bulk nested publish
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const publishDetails = {
environments:["{{env_uid}}","{{env_uid}}"],
locales:["en-us"],
items:[
{
  _content_type_uid: '{{content_type_uid}}',
  uid: '{{entry_uid}}'
},
{
  _content_type_uid: '{{content_type_uid}}',
  uid: '{{entry_uid}}'
},
{
  _content_type_uid: '{{content_type_uid}}',
  uid: '{{entry_uid}}'
}
]
}
client.stack({ api_key: 'api_key'}).bulkOperation().unpublish({ details:  publishDetails, is_nested: true })
.then((response) => {  console.log(response.notice) })

delete

The Delete entries and assets in bulk request allows you to delete multiple entries and assets at the same time.

Returns:
Type
Promise
NameTypeDescription

params.details

object

Set this with details specifing the content type UIDs, entry UIDs or asset UIDs, and locales of which the entries or assets you want to delete.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const publishDetails = {
  entries: [
    {
      uid: '{{entry_uid}}',
      content_type: '{{content_type_uid}}',
      locale: '{{entry_locale}}'
    }
  ],
  assets: [{
    uid: '{{uid}}'
  }]
}
client.stack({ api_key: 'api_key'}).bulkOperation().delete({ details:  publishDetails })
.then((response) => {  console.log(response.notice) })

Extension

Extensions let you create custom fields and custom widgets that lets you customize Contentstack's default UI and behavior. Read more about Extensions.

update

The Update Extension call lets you update an existing Extension.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).extension('extension_uid')
.fetch()
.then((extension) => {
 extension.title = 'My Extension Type'
 return extension.update()
})
.then((extension) => console.log(extension))

delete

The Delete Extension call is used to delete an existing Extension permanently from your Stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).extension('extension_uid')
.delete()
.then((response) => console.log(response.notice))

fetch

The fetch Extension call fetches Extension details.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).extension('extension_uid')
.fetch()
.then((extension) => console.log(extension))

upload

The Upload is used to upload a new custom widget, custom field, dashboard Widget to a stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const extension = {
 upload: 'path/to/file',
 title: 'Title',
 tags: [
   'tag1',
   'tag2'
 ],
 data_type: 'text',
 title: 'Old Extension',
 multiple: false,
 config: {},
 type: 'Type of extenstion you want to create widget/dashboard/field'
}
client.stack({ api_key: 'api_key'}).extension().upload(extension)
.then((extension) => console.log(extension))

create

The Create a extension call creates a new extension in a particular stack of your Contentstack account.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const extension = {
 tags: [
   'tag1',
   'tag2'
 ],
 data_type: 'text',
 title: 'Old Extension',
 src: "Enter either the source code (use 'srcdoc') or the external hosting link of the extension depending on the hosting method you selected.",
 multiple: false,
 config: {},
 type: 'field'
}
client.stack().extension().create({ extension })
.then((extension) => console.log(extension))

query

The Query on extension will allow to fetch details of all or specific extensions.

Returns:
Type
Promise
NameTypeDescription

params.include_count

boolean

Enter 'true' to include the count of extension

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).extension()
.query()
.find()
.then((extensions) => console.log(extensions))

Release

You can pin a set of entries and assets (along with the deploy action, i.e., publish/unpublish) to a ‘release’, and then deploy this release to an environment. This will publish/unpublish all the the items of the release to the specified environment.

update

The Update Release call lets you update the name and description of an existing Release.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const release = {
    name: "Release Name",
    description: "2018-12-12",
    locked: false,
    archived: false
}
var release = client.stack({ api_key: 'api_key'}).release('release_uid')
Object.assign(release, cloneDeep(release))
release.update()
.then((release) => console.log(release))

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).release('release_uid').fetch()
.then((release) => {
 release.title = 'My New release'
 release.description = 'Release description'
 return release.update()
})
.then((release) => console.log(release))

fetch

The fetch Release call fetches Release details.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).release('release_uid')
.fetch()
.then((release) => console.log(release))

delete

The Delete Release call is used to delete an existing Release permanently from your Stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).release('release_uid')
.delete()
.then((response) => console.log(response.notice))

item

A ReleaseItem is a set of entries and assets that needs to be deployed (published or unpublished) all at once to a particular environment.

Returns:
Type
ReleaseItem
NameTypeDescription

params.environments (required)

array

The environment(s) on which the Release should be deployed.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).release('release_uid').item()
.fetchAll()
.then((items) => console.log(items))

deploy

The Clone a Release request allows you to clone (make a copy of) a specific Release in a stack.

Returns:
Type
Promise
NameTypeDescription

params.environments (required)

array

The environment(s) on which the Release should be deployed.

params.locales

array

The locale(s) on which the Release should be deployed.

params.action

string

The action on which the Release should be deployed.

params. scheduledAt

string

The schedule time for the Release to deploy.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).release('release_uid').deploy({
     environments: [
                     "production",
                     "uat"
                     ],
     locales: [
                 "en-us",
                 "ja-jp"
              ],
     scheduledAt: '2018-12-12T13:13:13:122Z',
     action: 'publish',
})
.then((response) => console.log(response.notice))

clone

The Clone a Release request allows you to clone (make a copy of) a specific Release in a stack.

Returns:
Type
Promise
NameTypeDescription

params.name (required)

string

The name of the cloned Release.

params.description

string

description of the cloned Release.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).release('release_uid')
.clone({ name: 'New Name', description: 'New Description'})
.then((release) => console.log(release))

create

The Create a Release request allows you to create a new Release in your stack. To add entries/assets to a Release, you need to provide the UIDs of the entries/assets in ‘items’ in the request body.

Returns:
Type
Promise
NameTypeDescription

params.release

object

Release details.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const release = {
       name: "Release Name",
       description: "2018-12-12",
       locked: false,
       archived: false
}
client.stack({ api_key: 'api_key'}).release().create({ release })
.then((release) => console.log(release))

query

The Query on release will allow to fetch details of all or specific Releases.
Returns:
Type
Promise
NameTypeDescription

params.include_count

boolean

The include_count’ parameter includes the count of total number of releases in your stack, along with the details of each release.

params.include_items_count

boolean

The ‘include_items_count’ parameter returns the total number of items in a specific release.

params.limit

The ‘limit’ parameter will return a specific number of releases in the output.

params.skip

The ‘skip’ parameter will skip a specific number of releases in the response.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).release().query()
.find()
.then((release) => console.log(release))

ReleaseItem

A ReleaseItem is a set of entries and assets that needs to be deployed (published or unpublished) all at once to a particular environment.

delete

The Delete method request deletes one or more items (entries and/or assets) from a specific Release.

Returns:
Type
Promise
NameTypeDescription

params.item

object

Add a single item to a Release

params.items

object

Add multiple items to a Release

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).release('release_uid').delete()
.then((response) => console.log(response.notice))

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const items =  [
    {
       uid: "entry_or_asset_uid1",
       version: 1,
       locale: "en-us",
       content_type_uid: "demo1",
       action: "publish"
    },
    {
       uid: "entry_or_asset_uid2",
       version: 4,
       locale: "fr-fr",
       content_type_uid: "demo2",
       action: "publish"
     }
]
client.stack({ api_key: 'api_key'}).release('release_uid')
.item()
.create({ items })
.then((release) => console.log(release))

create

The Create method allows you to add an one or more items items (entry or asset) to a Release.

Returns:
Type
Promise
NameTypeDescription

params.item

object

Add a single item to a Release

params.items

object

Add multiple items to a Release

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const item = {
           version: 1,
           uid: "entry_or_asset_uid",
           content_type_uid: "your_content_type_uid",
           action: "publish",
           locale: "en-us"
}
client.stack({ api_key: 'api_key'}).release('release_uid')
.item()
.create({ item })
.then((release) => console.log(release))

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const items =  [
    {
       uid: "entry_or_asset_uid1",
       version: 1,
       locale: "en-us",
       content_type_uid: "demo1",
       action: "publish"
    },
    {
       uid: "entry_or_asset_uid2",
       version: 4,
       locale: "fr-fr",
       content_type_uid: "demo2",
       action: "publish"
     }
]
client.stack({ api_key: 'api_key'}).release('release_uid')
.item()
.create({ items })
.then((release) => console.log(release))

findAll

The Get all items in a Release request retrieves a list of all items (entries and assets) that are part of a specific Release.

Returns:
Type
Promise
NameTypeDescription

params.include_count

boolean

The include_count’ parameter includes the count of total number of items in Release, along with the details of each items.

params.limit

number

The ‘limit’ parameter will return a specific number of release items in the output.

params.skip

number

The ‘skip’ parameter will skip a specific number of release items in the response.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })

client.stack({ api_key: 'api_key'}).release('release_uid')
.item()
.findAll()
.then((items) => console.log(items))

Labels

Labels allow you to group a collection of content within a stack. Using labels you can group content types that need to work together. Read more about Labels.

update

The Update label call is used to update an existing label.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).label('label_uid')
.fetch()
.then((label) => {
 label.name = 'My New Content Type'
 return label.update()
})
.then((label) => console.log(label))

delete

The Delete label call is used to delete a specific label.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).label('label_uid').delete()
.then((response) => console.log(response.notice))

fetch

The fetch Label returns information about a particular label of a stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).label('label_uid').fetch()
.then((label) => console.log(label))

create

The Create a label call creates a new label.

Returns:
Type
Promise
NameTypeDescription

params.label

The label details you want to create with ContentType uid list.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const label = {
 name: 'First label',
 content_types: ['content_type_uid']
}
client.stack({ api_key: 'api_key'}).label()
.create({ label })
.then((label) => console.log(label))

query

The Query on Label will allow to fetch details of all or specific Label.

Returns:
Type
Query
NameTypeDescription

params.include_count

boolean

The include_count’ parameter includes the count of total number of label in your stack, along with the details of each label.

params.limit

The ‘limit’ parameter will return a specific number of label in the output.

params.skip

The ‘skip’ parameter will skip a specific number of label in the response.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).label()
.query({ query: { name: 'Label Name' } }).find()
.then((label) => console.log(label))

Locale

Contentstack has a sophisticated multilingual capability. It allows you to create and publish entries in any language. This feature allows you to set up multilingual websites and cater to a wide variety of audience by serving content in their local language(s). Read more about Locales.

update

The Update Locale call lets you update the name and description of an existing Locale.

Returns:
Type
Promise.<Locale.Locale>
NameTypeDescription

body

JSONObject

The request body

import * as contentstack from '@contentstack/management'
const client = contentstack.client()

client.stack({ api_key: 'api_key'}).locale('locale_code').fetch()
.then((locale) => {
  locale.fallback_locale = 'en-at'
  return locale.update()
})
.then((locale) => console.log(locale))

delete

The Delete Locale call is used to delete an existing Locale permanently from your Stack.

Returns:
Type
Object
import * as contentstack from '@contentstack/management'
const client = contentstack.client()

client.stack({ api_key: 'api_key'}).locale('locale_code').delete()
.then((response) => console.log(response.notice))

fetch

The fetch Locale call fetches Locale details.

Returns:
Type
Promise.<Locale.Locale>
NameTypeDescription

version

Int

UID of the content type of which you want to retrieve the details

import * as contentstack from '@contentstack/management'
const client = contentstack.client()

client.stack({ api_key: 'api_key'}).locale('locale_code').fetch()
.then((locale) => console.log(locale))

create

The Create a content type call creates a new content type in a particular stack of your Contentstack account.

Returns:
Type
Promise.<Locale.Locale>
NameTypeDescription

body

JSONObject

The request body

import * as contentstack from '@contentstack/management'
const client = contentstack.client()

client.stack().locale().create({ locale: { code: 'en-at' } )
.then((locale) => console.log(locale))

query

The Query on Content Type will allow to fetch details of all or specific Content Type

Returns:
Type
Array.<Locale>
NameTypeDescription

include_count

Boolean

Total count of content types available in your stack.

import * as contentstack from '@contentstack/management'
const client = contentstack.client()

client.stack(api_key).locale().query({ query: { code: 'locale-code' } }).find()
.then((locales) => console.log(locales))

AuditLog

An audit log displays a record of all the activities performed in a stack and helps you track all published items, updates, deletes, and the current status of the existing content.

fetch

The fetch AuditLog call fetches AuditLog details.

Returns:
Type
Promise.<Branch.Branch>
NameTypeDescription

audit_log_item_uid

string

UID of the audit log item

import * as contentstack from '@contentstack/management'
const client = contentstack.client()

client.stack({ api_key: 'api_key'}).auditLog('audit_log_item_uid').fetch()
.then((log) => console.log(log))

fetchAll

The fetchAll method retrieves the details of all the branches of a stack.

Returns:
Type
ContentstackCollection
NameTypeDescription

limit

Int

Limit on API response to provide content in the list

skip

Int

Offset for skipping content in response

include_count

Boolean

To retrieve the count of Branch.

import * as contentstack from '@contentstack/management'
const client = contentstack.client()

client.stack({ api_key: 'api_key'}).auditLog().fetchAll()
.then((logs) => console.log(logs))

Environment

A publishing environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published.

update

The Update Environment call lets you update the name and description of an existing Environment.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).environment('name')
.fetch()
.then((environment) => {
 environment.title = 'My New Content Type'
 environment.description = 'Content Type description'
 return environment.update()
})
.then((environment) => console.log(environment))

delete

The Delete Environment call is used to delete an existing Environment permanently from your Stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).environment('name')
.delete()
.then((response) => console.log(response.notice))

fetch

The fetch Environment call fetches Environment details.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).environment('name')
.fetch()
.then((environment) => console.log(environment))

create

The Create a Environment call creates a new environment in a particular stack of your Contentstack account.

Returns:
Type
Promise
NameTypeDescription

params.environments

object

The environment details with name, server, urls, and deploy content.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const environment = {
     name: 'development',
     servers: [
               {
                 name: 'default'
               }
               ],
     urls: [
             {
                 locale: 'en-us',
                 url: 'http://example.com/'
             }
           ],
     deploy_content: true
}
client.stack({ api_key: 'api_key'}).environment().create({ environment })
.then((environment) => console.log(environment))

query

The Query on Environment will allow to fetch details of all or specific Environment.

Returns:
Type
Query
NameTypeDescription

params.include_count

boolean

The `include_count’ parameter includes the count of total number of environment in your stack, along with the details of each environment.

params.limit

The ‘limit’ parameter will return a specific number of environment in the output.

params.skip

The ‘skip’ parameter will skip a specific number of environment in the response.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).environment()
.query({ query: { name: 'Environment Name' } }).find()
.then((environment) => console.log(environment))

DeliveryToken

Delivery tokens provide read-only access to the associated environments.

update

The update method allows you to modify the existing management token within the stack.

Returns:
Type
Promise

Example:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).managementToken('management_token_uid')
.fetch()
.then((managementToken) => {
 managementToken.title = 'My New management token'
 managementToken.description = 'management token description'
 return managementToken.update()
})
.then((managementToken) => console.log(managementToken))

delete

The Delete DeliveryToken call is used to delete an existing DeliveryToken permanently from your Stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).deliveryToken('delivery_token_uid')
.delete()
.then((response) => console.log(response.notice))

fetch

The fetch DeliveryToken call fetches DeliveryToken details.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).deliveryToken('delivery_token_uid')
.fetch()
.then((deliveryToken) => console.log(deliveryToken))

create

The Create a DeliveryToken call creates a new deliveryToken in a particular stack of your Contentstack account.

Returns:
Type
Promise
NameTypeDescription

params.toekn

object

The token details with name, description and scope for the token to be created.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const token = {
    name: 'Test',
    description: 'This is a demo token.',
    scope: [{
             module: 'environment',
             environments: ['development'],
             acl: {
               read: true
             }
           }]
}
client.stack({ api_key: 'api_key'}).deliveryToken()
.create({ token })
.then((deliveryToken) => console.log(deliveryToken))

query

The ‘Get all deliveryToken’ request returns comprehensive information about all deliveryToken created in a stack.

Returns:
Type
Query
NameTypeDescription

params.include_count

boolean

The `include_count’ parameter includes the count of total number of delivery token in your stack, along with the details of each delivery token

params.limit

The ‘limit’ parameter will return a specific number of delivery token in the output.

params.skip

The ‘skip’ parameter will skip a specific number of delivery token in the response.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).deliveryToken()
.query({ query: { name: 'token_name' } }))
.find()
.then((contentstackCollection) => console.log(contentstackCollection))

ManagementToken

Management Tokens are tokens that provide you with read-write access to your stack's content. When used in conjunction with the stack API key, they authorize Content Management API (CMA) requests for the purpose of managing your stack's content.

update

The update method allows you to modify the existing management token within the stack.

Returns:
Type
Promise

Example:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).managementToken('management_token_uid')
.fetch()
.then((managementToken) => {
 managementToken.title = 'My New management token'
 managementToken.description = 'management token description'
 return managementToken.update()
})
.then((managementToken) => console.log(managementToken))

delete

The delete method removes the existing management token from the stack.

Returns:
Type
Promise

Example:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).managementToken('management_token_uid')
.delete()
.then((response) => console.log(response.notice))

fetch

The fetch method retrieves the details of a specific management token from the stack.

Returns:
Type
Promise

Example:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).managementToken('management_token_uid')
.fetch()
.then((managementToken) => console.log(managementToken))

create

The create method allows you to create a new management token in the stack.

Returns:
Type
Promise
NameTypeDescription

params.token

object

The details of the token, including its name, description, and scope, are specified for the token to be created

Example:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const token = {
    "token":{
      "name":"Test Token",
      "description":"This is a sample management token.",
      "scope":[
          {
              "module":"content_type",
              "acl":{
                  "read":true,
                  "write":true
              }
          },
          {
              "module":"branch",
              "branches":[
                  "main"
              ],
              "acl":{
                  "read":true
              }
          },
          {
              "module":"branch_alias",
              "branch_aliases":[
                  "tst"
              ],
              "acl":{
                  "read":true
              }
          }
      ],
      "expires_on":"2024-12-10",
      "is_email_notification_enabled":true
  }
}
client.stack({ api_key: 'api_key'}).managementToken()
.create({ token })
.then((managementToken) => console.log(managementToken))

query

The Get all managementToken request retrieves comprehensive information about all the management tokens created in a stack.

Returns:
Type
Query
NameTypeDescription

params.include_count

boolean

The include_count parameter includes the total count of management tokens in your stack, along with the details of each individual management token.

params.limit

int

The limit parameter retrieves a specific number of management tokens in the output.

params.skip

int

The skip parameter will skip a specific number of management tokens in the response.

Example:

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).managementToken()
.query({ query: { name: 'token_name' } }))
.find()
.then((contentstackCollection) => console.log(contentstackCollection))

Role

A role is a collection of permissions that will be applicable to all the users who are assigned this role.

update

The Update role call lets you modify an existing role of your stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).role('role_uid')
.fetch({ include_rules: true, include_permissions: true})
.then((role) => {
 role.name = 'My New Role'
 role.description = 'Role description'
 role.rules = [
{
  module: 'asset',
  assets: ['$all'],
  acl: {
    read: true,
    create: true,
    update: true,
    publish: true,
    delete: true
  }
},
{
  module: 'environment',
  environments: [],
  acl: { read: true }
},
{
  module: 'locale',
  locales: [Array],
  acl: { read: true }
}]
 return role.update()
})
.then((role) => console.log(role))

delete

The Delete role call deletes an existing role from your stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).role('role_uid').delete()
.then((response) => console.log(response.notice))

create

The ‘Get all roles’ request returns comprehensive information about all roles created in a stack.

Returns:
Type
Promise
NameTypeDescription

params.role

object

The role details with name, description and rules to be created.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const role =  {
  name: 'Role Name',
  description: 'From CMA Js',
  rules:
    [
      {
        module: 'environment',
        environments: [],
        acl: { read: true }
      },
      {
        module: 'locale',
        locales: [],
        acl: { read: true }
      }
    ],
}
client.stack({ api_key: 'api_key'}).role()
.create({ role })
.then((role) => console.log(role))

fetch

The Get a single role request returns comprehensive information on a specific role.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).role('role_uid').fetch()
.then((role) => console.log(role))

fetchAll

The ‘Get all roles’ request returns comprehensive information about all roles created in a stack.

Returns:
Type
Promise
NameTypeDescription

params.include_count

boolean

The `include_count’ parameter includes the count of total number of role in your stack, along with the details of each role.

params.include_permissions

boolean

Set this parameter to 'true' to include the details of the permissions assigned to a particular role.

params.limit

number

The ‘limit’ parameter will return a specific number of role in the output.

params.skip

number

The ‘skip’ parameter will skip a specific number of role in the response.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).role()
.fetchAll()
.then((role) => console.log(role))

query

The Query on Role will allow to fetch details of all or specific role.

Returns:
Type
Query
NameTypeDescription

params.include_count

boolean

The `include_count’ parameter includes the count of total number of role in your stack, along with the details of each role.

params.include_permissions

boolean

Set this parameter to 'true' to include the details of the permissions assigned to a particular role.

params.limit

number

The ‘limit’ parameter will return a specific number of role in the output.

params.skip

number

The ‘skip’ parameter will skip a specific number of role in the response.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).role()
.query({ query: { filename: 'Asset Name' } })
.find()
.then((role) => console.log(role))

Webhook

A webhook is a mechanism that sends real-time information to any third-party app or service to keep your application in sync with your Contentstack account. Webhooks allow you to specify a URL to which you would like Contentstack to post data when an event happens. 

update

The Update Webhook call lets you update the name and description of an existing Webhook.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).webhook('webhook_uid')
.fetch()
.then((webhook) => {
 webhook.title = 'My New Webhook'
 webhook.description = 'Webhook description'
 return webhook.update()
})
.then((webhook) => console.log(webhook))

delete

The Delete Webhook call is used to delete an existing Webhook permanently from your Stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).webhook('webhook_uid')
.delete()
.then((response) => console.log(response.notice))

fetch

The fetch Webhook call fetches Webhook details.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).webhook('webhook_uid')
.fetch()
.then((webhook) => console.log(webhook))

executions

The Get executions of a webhook call will provide the execution details of a specific webhook, which includes the execution UID.
Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).webhook('webhook_uid')
.executions()
.then((webhook) => console.log(webhook))

retry

The retry webhook execution will perform retry execution.

Returns:
Type
Promise
NameTypeDescription

executionUid

string

execution UID that you receive when you execute the 'Get executions of webhooks' call.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'})
.create({ webhook })
.then((webhook) => console.log(webhook))

create

The Create a webhook request allows you to create a new webhook in a specific stack.

Returns:
Type
Promise
NameTypeDescription

params.webhook

object

The webhook details including name, destinations, channels, and retry policy.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const webhook = {
name: 'Test',
destinations: [{
  target_url: 'http://example.com',
  http_basic_auth: 'basic',
  http_basic_password: 'test',
  custom_header: [{
    header_name: 'Custom',
    value: 'testing'
  }]
}],
 channels: [
   'assets.create'
 ],
 retry_policy: 'manual',
 disabled: false
}
client.stack({ api_key: 'api_key'}).webhook()
.create({ webhook })
.then((webhook) => console.log(webhook))

fetchAll

The Get all Webhook call lists all Webhooks from Stack.

Returns:
Type
Promise
NameTypeDescription

params.include_count

boolean

The `include_count’ parameter includes the count of total number of webhook in your stack, along with the details of each webhook.

params.limit

number

The ‘limit’ parameter will return a specific number of webhook in the output.

params.skip

number

The ‘skip’ parameter will skip a specific number of webhook in the response.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).webhook()
.fetchAll()
.then((webhook) => console.log(webhook))

import

The Import a web hook call imports a web hook into a stack.

Returns:
Type
Promise
NameTypeDescription

params.webhook (required)

string

File path to import webhook

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const data = {
 webhook: 'path/to/file.json',
}
client.stack({ api_key: 'api_key'}).webhook().import(data)
.then((webhook) => console.log(webhook))
//OR
client.stack({ api_key: 'api_key'}).webhook('webhook_uid').import(data)
.then((webhook) => console.log(webhook))

Workflow

Workflow is a tool that allows you to streamline the process of content creation and publishing, and lets you manage the content lifecycle of your project smoothly.

update

The Update Workflow request allows you to add a workflow stage or update the details of the existing stages of a workflow.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).workflow('workflow_uid').fetch()
.then((workflow) => {
 workflow.name = 'My New Workflow'
 workflow.description = 'Workflow description'
 return workflow.update()
})
.then((workflow) => console.log(workflow))

disable

The Disable Workflow request allows you to disable a workflow.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).workflow('workflow_uid')
.disable()
.then((workflow) => console.log(workflow))

enable

The Enable Workflow request allows you to enable a workflow.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).workflow('workflow_uid')
.enable()
.then((workflow) => console.log(workflow))

delete

The Delete Workflow call is used to delete an existing Workflow permanently from your Stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).workflow('workflow_uid')
.delete()
.then((response) => console.log(response.notice))

fetch

The fetch workflow retrieves the comprehensive details of a specific Workflow of a stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).workflow('workflow_uid')
.fetch()
.then((workflow) => console.log(workflow))

create

The get Workflow call is used to get details of an existing Workflow from your Stack.

Returns:
Type
Promise
NameTypeDescription

params.action

string

Enter the action that has been set in the Publishing Rule. Example:publish/unpublish

params.locale

string

Enter the code of the locale where your Publishing Rule will be applicable.

environment

string

Enter the UID of the environment where your Publishing Rule will be applicable.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).workflow()
.contentType('contentType_uid')
.getPublishRules()
.then((collection) => console.log(collection))

create

The Create a Workflow request allows you to create a Workflow.

Returns:
Type
Promise
NameTypeDescription

params.workflow

object

The workflow details with workflow stages.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const workflow = {
"workflow_stages": [
     {
       "color": "#2196f3",
       "SYS_ACL": {
         "roles": {
           "uids": []
         },
         "users": {
         "uids": [
           "$all"
         ]
       },
       "others": {}
     },
     "next_available_stages": [
       "$all"
     ],
     "allStages": true,
     "allUsers": true,
     "specificStages": false,
     "specificUsers": false,
     "entry_lock": "$none", 
     "name": "Review"
   },
   {
     "color": "#74ba76",
     "SYS_ACL": {
       "roles": {
         "uids": []
       },
       "users": {
         "uids": [
           "$all"
         ]
       },
       "others": {}
     },
     "allStages": true,
     "allUsers": true,
     "specificStages": false,
     "specificUsers": false,
     "next_available_stages": [
         "$all"
       ],
       "entry_lock": "$none",
       "name": "Complete"
     }
   ],
   "admin_users": {
     "users": []
   },
     "name": "Workflow Name",
     "enabled": true,
     "content_types": [
       "$all"
     ]
 }
client.stack({ api_key: 'api_key'}).workflow()
.create({ workflow })
.then((workflow) => console.log(workflow))

fetchAll

The Get all Workflows request retrieves the details of all the Workflows of a stack.

Returns:
Type
Promise
NameTypeDescription

params.limiit

number

The limit parameter will return a specific number of workflow in the output.

params.skip

number

The skip parameter will skip a specific number of workflow in the output.

params.include_count

boolean

To retrieve the count of workflow.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).workflow()
.fetchAll()
.then((collection) => console.log(collection))

publishRule

The Publish rule allow you to create, fetch, delete, update the publish rules.

Returns:
Type
Promise
NameTypeDescription

uid

string

Uid for publish rule.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).workflow().publishRule().fetchAll()
.then((collection) => console.log(collection))
client.stack({ api_key: 'api_key'}).workflow().publishRule('rule_uid').fetch()
.then((publishrule) => console.log(publishrule))

PublishRules

PublishRules is a tool that allows you to streamline the process of content creation and publishing, and lets you manage the content lifecycle of your project smoothly.

create

The Create Publish Rules request allows you to create publish rules for the publish rules of a stack.

Returns:
Type
Promise
NameTypeDescription

params.workflow

object

The workflow details with workflow stages.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const publishing_rule = {
   	"publish rules": "publish rules_uid",
       "actions": [],
       "content_types": ["$all"],
       "locales": ["en-us"],
       "environment": "environment_uid",
        "approvers": {
       	"users": ["user_uid"],
       	"roles": ["role_uid"]
       },
       "publish rules_stage": "publish rules_stage_uid",
        "disable_approver_publishing": false
}
client.stack({ api_key: 'api_key'}).publishRules()
.create({ publishing_rule })
.then((publishRules) => console.log(publishRules))

Taxonomy

Taxonomy helps you categorize pieces of content within your stack to facilitate easy navigation, search, and retrieval of information. You can hierarchically organize your web properties based on your requirements, such as their purpose, target audience, or any other aspects of your business.

create

The create method lets you create a new taxonomy in your stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
const taxonomy = {
	uid: 'taxonomy_testing1',
	name: 'taxonomy testing',
	description: 'Description for Taxonomy testing'
}
client.stack({ api_key: 'api_key'}).taxonomy().create({taxonomy})
.then((taxonomy) => console.log(taxonomy))

fetch

The fetch method retrieves the details of a specific taxonomy in your stack.

Returns:
Type
Promise
NameTypeDescription

taxonomyUid (required)

string

UID of the taxonomy

include_terms_count

boolean

Include count of all the terms that are in the taxonomy

include_referenced_terms_count

boolean

Include count of the terms which are referred in atleast 1 entry

include_referenced_entries_count

boolean

Include count of the entries where atleast 1 term of this taxonomy is referred

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').fetch().then((taxonomy) => console.log(taxonomy))

query

The query method retrieves the details of all the existing taxonomies in your stack.

Returns:
Type
Promise
NameTypeDescription

include_terms_count

boolean

Include count of all the terms that are in the taxonomy

include_referenced_terms_count

boolean

Include count of the terms which are referred in atleast 1 entry

include_referenced_entries_count

boolean

Include count of the entries where atleast 1 term of this taxonomy is referred

include_count

boolean

Include count of the taxonomies that matched the query

asc|desc

string

Sort the given field in either ascending or descending order

query

string

Used to give a custom query in a string format, currently restricted to only query on uid

typeahead

string

Used to match the given string in all taxonomies & return the matched result

deleted

boolean

Used to fetch only the deleted taxonomies

skip

number

Skip the number of taxonomies

limit

number

Limit the result to number of taxonomies

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).taxonomy().query().find().then((taxonomy) => console.log(taxonomy))

update

The update method lets you update an existing taxonomy in your stack.

Returns:
Type
Promise
NameTypeDescription

taxonomyUid (required)

string

UID of the taxonomy

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').fetch() .then((taxonomy) => {
	taxonomy.name = 'taxonomy name'
	return taxonomy.update()
})
.then((taxonomy) => console.log(taxonomy))

delete

The delete method lets you remove an existing taxonomy from the stack.

Returns:
Type
Promise
NameTypeDescription

taxonomyUid (required)

string

UID of the taxonomy

force

boolean

Setting this to true will force delete the taxonomy and all its child terms. By default it is set to false.

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').delete().then((taxonomy) => console.log(taxonomy))

Terms

Terms are the fundamental building blocks in a taxonomy. They are used to create hierarchical structures and are integrated into entries to classify and categorize information systematically.

create

The create method lets you add a new term to your taxonomy.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
const term = {
	uid: 'termUid',
	name: 'term name',
	parent_uid: 'parent_uid',
	order: 2
}
client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid')
terms().create(term)
.then((term) => console.log(term))

fetch

The fetch method is used to retrieve the information about a specific term in your taxonomy.

Returns:
Type
Promise
NameTypeDescription

include_children_count

boolean

Include count of number of children under each term

include_referenced_entries_count

boolean

Include count of the entries where this term is referred

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').terms('termUid').fetch().then((term) => console.log(term))

query

The query method is used to retrieve the information of all the terms in your taxonomy.

Returns:
Type
Promise
NameTypeDescription

depth

number

Include the terms from the root upto the depth specified if set to a number greater than 0, include all the terms if set to 0, default depth will be set to 1

include_children_count

boolean

Include count of number of children under each term if set to true

include_referenced_entries_count

boolean

Include count of the entries where this term is referred

include_count

boolean

Include count of the terms that matched the query

include_order

boolean

Include order of the terms relative to their siblings

asc|desc

string

Sort the given field in either ascending or descending order

skip

number

Skip the number of terms

limit

number

Limit the result to number of terms

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').terms().query().find().then((terms) => console.log(terms))

update

The update method is used to update the details of an exisiting term in the taxonomy.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').terms('termUid').fetch().then((term) => {
	term.name = 'taxonomy name'
	return term.update()
})
.then((term) => console.log(term))

delete

The delete method lets you remove an existing term from a taxonomy.

Returns:
Type
Promise
NameTypeDescription

force

boolean

Setting this to true will force delete the taxonomy and all its child terms. By default it is set to false.

termUid (required)

string

UID of the term

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').term('termUid').delete()
.then((response) => console.log(response.notice))

ancestors

The ancestors method is used to retrieves the list of all the ancestors of an existing term

Returns:
Type
Promise
NameTypeDescription

termUid (required)

string

UID of the term

include_children_count

boolean

Include count of number of children under each term

include_referenced_entries_count

boolean

Include count of the entries where atleast 1 term of this taxonomy is referred

include_count

boolean

Include count of the terms that matched the query

skip

number

Skip the number of terms

limit

number

Limit the result to number of terms

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').term('termUid').ancestors()
.then((terms) => console.log(terms))

descendants

The descendants method is used to retrieves the list of all the descendants of an existing term.

Returns:
Type
Promise
NameTypeDescription

termUid (required)

string

UID of the term

depth

number

Include the terms from the current term’s depth, upto the depth specified if set to a number greater than 0, include all the terms from the current term’s depth if set to 0, default depth will be set to 1, which will be to include the immediate terms from the current term’s depth

include_children_count

boolean

Include count of number of children under each term

include_referenced_entries_count

boolean

Include count of the entries where atleast 1 term of this taxonomy is referred

include_count

boolean

Include count of the terms that matched the query

include_order

boolean

Include order of the terms relative to their siblings

skip

number

Skip the number of terms

limit

number

Limit the result to number of terms

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').term('termUid').descendants()
.then((terms) => console.log(terms))

move

The move method lets you move an existing term or change the parent UID of the term.

Returns:
Type
Promise
NameTypeDescription

termUid (required)

string

UID of the term

force

boolean

Setting this to true will force delete the taxonomy and all its child terms. By default it is set to false.
import * as contentstack from '@contentstack/management'
const client = contentstack.client()
const term = {
	parent_uid: 'parent_uid',
	order: 2
}
client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').terms('termUid').move({term})
.then((term) => console.log(term))

search

The search method lets you search an existing term in the taxonomy.

Returns:
Type
Promise
NameTypeDescription

termUid (required)

string

UID of the term

include_children_count

boolean

Include count of number of children under each term

include_referenced_entries_count

boolean

Include count of the entries where atleast 1 term of this taxonomy is referred

include_count

boolean

Include count of the terms that matched the query

query

string

Used to give a custom query in a string format, currently restricted to only query on taxonomy_uid & term_uid

typeahead

string

Used to match the given string in all terms & return the matched result, should either match with term uid or term name

skip

number

Skip the number of terms

limit

number

Limit the result to number of terms

import * as contentstack from '@contentstack/management'
const client = contentstack.client()
client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').terms().search('termString').then((term) => console.log(term))

Teams

Teams streamline the process of assigning roles and permissions by grouping users together. Rather than assigning roles to individual users or at the stack level, you can assign roles directly to a team. This ensures that all users within a team share the same set of role permissions, making role management more efficient.

fetch

The fetch method retrieves details of a specific team.

Returns:
Type
Promise
NameTypeDescription

includeUserDetails

boolean

If true, include detailed user information for team members; otherwise, include only user UIDs.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.organization('organization_uid').teams('teamUid').fetch()
.then((team) => console.log(team)

create

The create method creates a new team.

Returns:
Type
Promise
NameTypeDescription

includeUserDetails

boolean

If true, include detailed user information for team members; otherwise, include only user UIDs.

team

object

Details required for team creation.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const team = { 
name: 'name', 
organizationUid: 'organization_uid', 
users: [], 
stackRoleMapping: [], 
organizationRole: 'organizationRole'
}

client.organization('organizationUid').teams().create(team)
.then((response) => console.log(response))

fetchAll

The fetchAll method retrieves the details of all teams.

Returns:
Type
Promise
NameTypeDescription

includeUserDetails

boolean

If true, include detailed user information for team members; otherwise, include only user UIDs.

asc|desc

string

Sort in either ascending or descending order

typeahead

string

Used to match the given string in all teams name & return the matched result

skip

number

Skip the number of teams

limit

number

Limit the result to number of teams

user_uid

comma separated string

list of user UIDs to be filtered

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })

client.organization('organizationUid').teams().fetchAll()
.then((teams) => console.log(teams))

delete

The delete method deletes an existing team.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })

client.organization('organization_uid').teams('teamUid').delete()
.then((response) => console.log(response)

update

The update method involves adding and removing users from teams, assigning and removing stack roles within teams, updating team descriptions, and adjusting team organization roles.

Returns:
Type
Promise
NameTypeDescription

includeUserDetails

boolean

If true, include detailed user information for team members; otherwise, include only user UIDs.

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const updateData = {
name: 'updatedname',
users: [{
email: 'abc@abc.com'
}],
organizationRole: 'blt09e5dfced326aaea',
stackRoleMapping: []
}

client.organization(s'organizationUid').teams('teamUid').update(updateData)
.then((response) => console.log(response))

TeamUsers

The TeamUsers method retrieves the UIDs of the users.

Returns:
Type
teamUsers
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })

client.organization('organizationUid').teams('teamUid').teamUsers().fetchAll()
.then((response) => console.log(response))

stackRoleMappings

The stackRoleMappings method retrieves the stack role mapping details.

Returns:
Type
stackRoleMappings
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })

client.organization(s'organizationUid').teams('teamUid').stackRoleMappings().fetchAll()
.then((response) => console.log(response))

TeamUsers

The TeamUsers methods allows uou to retrieve, add, and remove users from a team.

add

The add method adds an user to the team.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const usersMail = {
emails: ['emailId1','emailId2' ]
}

client.organization('organizationUid').teams('teamUid').teamUsers('userId').add(usersMail)
.then((response) => console.log(response))

fetchAll

The fetchAll method allows you to fetch all details of the users of a team.

Returns:
Type
Promise
NameTypeDescription

includeUserDetails

boolean

If true, include detailed user information for team members; otherwise, include only user UIDs.

include_count

boolean

Include total count of users

import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })

client.organization('organizationUid').teams('teamUid').teamUsers('userId').fetchAll()
.then((users) => console.log(users))

remove

The remove method removes an user from the team.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })

client.organization('organization_uid').teams('teamUid').teamUsers('userId').remove()
.then((response) => console.log(response)

StackRoleMappings

The StackRoleMappings methods allows you to retrieve, add, update and delete users from a team.

add

The add method adds an user to the team.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const addRole = {
stackApiKey: 'stackApiKey',
roles: ['role_uid']
}
client.organization('organizationUid').teams('teamUid').stackRoleMappings().add(addRole)
.then((response) => console.log(response))

fetchAll

The fetchAll method allows you to fetch all details of the roles of that team.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })

client.organization('organizationUid').teams('teamUid').stackRoleMappings().fetchAll()
.then((response) => console.log(response))

delete

The delete method deletes all roles of the stack.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })

client.organization('organization_uid').teams('teamUid').stackRoleMappings('stackApiKey').delete()
.then((response) => console.log(response)

update

The update method is used to update the roles.

Returns:
Type
Promise
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const updateRoles = {
roles: ['role_uid1', 'role_uid2']
}

client.organization('organizationUid').teams('teamUid').stackRoleMappings('stackApiKey').update(updateRoles)
.then((response) => console.log(response))