Stack
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
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
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.
| Name | Type | Description |
|---|---|---|
| uid | string | UID for content type to perform operation 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.
| Name | Type | Description |
|---|---|---|
| uid | string | UID for locale to perform operation 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.
| Name | Type | Description |
|---|---|---|
| uid | string | UID for asset to perform operation 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
A Global field is a reusable field (or group of fields) that you can define once and reuse in any content type within your stack.
| Name | Type | Description |
|---|---|---|
| uid | string | UID for GlobalField to perform operation 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.
| Name | Type | Description |
|---|---|---|
| uid | string | UID for environment to perform operation 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
| Name | Type | Description |
|---|---|---|
| uid | string | UID for branch alias to perform operation 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
Branch Alias is a custom name given to a specific branch in a stack to make referencing easier, especially when working with multiple branches.
| Name | Type | Description |
|---|---|---|
| uid | string | UID for branch alias to perform operation 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.
| Name | Type | Description |
|---|---|---|
| uid | string | UID for delivery token to perform operation 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.
| Name | Type | Description |
|---|---|---|
| uid | string | UID for extension to perform operation 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
| Name | Type | Description |
|---|---|---|
| uid | string | UID for workflow to perform operation 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.
| Name | Type | Description |
|---|---|---|
| uid | string | UID for webhook to perform operation 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
| Name | Type | Description |
|---|---|---|
| uid | string | UID for label to perform operation 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.
| Name | Type | Description |
|---|---|---|
| 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.
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
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.
| Name | Type | Description |
|---|---|---|
| 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.
| Name | Type | Description |
|---|---|---|
| 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({ 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.
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
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.
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
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.
| Name | Type | Description |
|---|---|---|
| param (required) | object | Object for adding to the stack settings |
Example 1:
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).addSettings({ key: 'value' })
.then((settings) => console.log(settings))Example 2:
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const variables = {
stack_variables: {
enforce_unique_urls: true,
sys_rte_allowed_tags: "style,figure,script",
sys_rte_skip_format_on_paste: "GD:font-size"
},
rte: {
cs_breakline_on_enter: true,
cs_only_breakline: true
},
live_preview: {
enabled: true,
"default-env": "blt123123123123",
"default-url": "https://preview.example.com"
}
};
client.stack({ api_key: 'api_key'}).addSettings(variables)
.then((settings) => console.log(settings)share
The Share a stack call shares a stack with the specified user to collaborate on the stack.
| Name | Type | Description |
|---|---|---|
| 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({ api_key: 'api_key'}).share([ "[email protected]" ], { "[email protected]": [ "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.
| Name | Type | Description |
|---|---|---|
| email (required) | string | Email id to unshare stack. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).unShare('[email protected]')
.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.
| Name | Type | Description |
|---|---|---|
| role_uid | string | Role uid for initiating role class |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).role()
//or
<span>client.stack({ api_key: 'api_key'}).role('role_uid')</span>create
The Create stack call creates a new stack in your Contentstack account.
| Name | Type | Description |
|---|---|---|
| params.stack.name (required) | string | Name for the stack |
| params.stack.master_locale (required) | string | Master locale for the Stack. |
| param.stack.description | String | 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() method returns a query builder. Pass optional query parameters, which are stored until any one of the following terminal methods is called:
- find(): Retrieves multiple stacks as a ContentstackCollection.
- findOne(): Retrieves at most one stack as a ContentstackCollection (items[0]).
- count(): Returns the total count by merging count: true into the request and returning response.data.
Note The find() method performs a single API request and returns a ContentstackCollection. Page size and offset are controlled via limit and skip in query(). Omitting them uses API defaults.
| Name | Type | Description |
|---|---|---|
| params.query | object | Top-level query object for filtering stacks. Sibling keys can include pagination and include flags. |
| params.include_collaborators | boolean | When true, it includes the details of the stack collaborators in the response. |
| params.include_stack_variables | boolean | When true, includes stack variables in the response (e.g., description, date format, time format). Response includes stack variable details. |
| params.include_discrete_variables | boolean | When true, it includes your stack's access token in the response. Response includes discrete variables. |
| params.include_count | boolean | When true, includes the total count of stacks owned by or shared with your account. Response includes a count. |
Example: Fetch a filtered list of stacks in a single request.
Note Each include_* flag can increase response size and transfer time. Request only the expansions your app needs.
import * as contentstack from '@contentstack/management'
const client = contentstack.client({
authtoken: '<AUTHTOKEN>',
})
client
.stack()
.query({
query: { name: '<STACK_NAME>' },
limit: 20,
skip: 0,
include_count: true,
include_collaborators: true,
include_stack_variables: true,
include_discrete_variables: true,
})
.find()
.then((stacks) => console.log(stacks))
.catch((err) => console.error(err))Example: Get the total count of stacks matching the query
import * as contentstack from '@contentstack/management'
const client = contentstack.client({
authtoken: '<AUTHTOKEN>',
})
client
.stack()
.query({
query: { name: '<STACK_NAME>' },
limit: 20,
skip: 0,
include_count: true,
include_collaborators: true,
include_stack_variables: true,
include_discrete_variables: true,
})
.count()
.then((data) => console.log(data))
.catch((err) => console.error(err))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.
| Name | Type | Description |
|---|---|---|
| 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))