cs-icon.svg

JavaScript Delivery SDK

Note: We recommend using the TypeScript Delivery SDK as a preferred option over the JavaScript Delivery SDK for optimal performance and enhanced functionality in your project. Learn to seamlessly migrate from JavaScript to TypeScript.

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. Build your application frontend, and Contentstack will take care of the rest. Read More.

Contentstack provides JavaScript Delivery SDK to build application on top of JavaScript. Given below is the detailed guide and helpful resources to get started with our JavaScript Delivery SDK.

The JavaScript Delivery SDK can also be used to create Node.js and React native applications.

Prerequisite

You need Node.js version 20 or later or later installed to use the Contentstack JavaScript Delivery SDK.

Setup and Installation

For JavaScript (Browser)

For browsers, we recommend to download the library via npm or yarn to ensure 100% availability.

If you'd like to use a standalone built file you can use the following script tag or download it from jsDelivr, under the `dist` directory:

<script src="https://cdn.jsdelivr.net/npm/contentstack@latest/dist/web/contentstack.min.js"></script>

You can also specify a specific version number.

<script src="https://cdn.jsdelivr.net/npm/contentstack@3.16.0/dist/web/contentstack.min.js"></script>

To initialize the SDK, you will need to specify the API Key, Delivery Token, and Environment Name of your stack.

const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment":"environment"});           

To initialize the SDK for the Europe, Azure NA, Azure EU region, or GCP NA refer to the code below:

FOR EU
const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment":"environment","region":Contentstack.Region.EU});
FOR AZURE_EU
const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment":"environment","region":Contentstack.Region.AZURE_EU});
FOR AZURE_NA
const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment":"environment","region":Contentstack.Region.AZURE_NA});
FOR GCP_NA
const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment":"environment","region":Contentstack.Region.GCP_NA});

To initialize the SDK with Early Access Header, refer to the code below:

const Stack = Contentstack.Stack({
    'api_key':'api_key',
    'delivery_token':'delivery_token',
    'environment':'environment_name',
    'early_access': ['early_access_1', 'early_access_2']
});

For Node.js

Node.js uses the Javascript SDK to create apps. To use the JavaScript Delivery SDK, install it via npm:

npm i contentstack           

To import the SDK in your project, use the following command:

import Contentstack from 'contentstack';

To initialize the SDK, you will need to specify the API Key, Delivery Token, and Environment Name of your stack.

const Stack = Contentstack.Stack({ "api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment");

To initialize the SDK for the Europe, Azure NA, Azure EU, or GCP NA region, refer to the code below:

FOR EU
const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment":"environment","region":Contentstack.Region.EU});
FOR AZURE_EU
const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment":"environment","region":Contentstack.Region.AZURE_EU});
FOR AZURE_NA
const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment": "environment","region":Contentstack.Region.AZURE_NA });
FOR GCP_NA
const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment":"environment","region":Contentstack.Region.GCP_NA});

For React Native

React Native uses the Javascript SDK to create apps. To use the JavaScript Delivery SDK, install ist via npm:

npm i contentstack

To import the SDK in your project, use the following command:

import Contentstack from 'contentstack/react-native'

To initialize the SDK, you will need to specify the API Key, Delivery Token, and Environment Name of your stack.

const Stack = Contentstack.Stack({ "api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment" });

To initialize the SDK for the Europe, Azure NA, Azure EU, or GCP NA region, refer to the code below:

FOR EU
const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment":"environment","region":Contentstack.Region.EU});
FOR AZURE_EU
const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment":"environment","region":Contentstack.Region.AZURE_EU});
FOR AZURE_NA
const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment": "environment", "region": Contentstack.Region.AZURE_NA});
FOR GCP_NA
const Stack = Contentstack.Stack({"api_key":"api_key","delivery_token":"delivery_token","environment":"environment","region":Contentstack.Region.GCP_NA});

Quickstart in 5 mins

Initializing your SDK

You will need to specify the API key, Delivery token, and Environment Name of your stack to initialize the SDK:

const Stack = Contentstack.Stack({ "api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment" });

Once you have initialized the SDK, you can start getting content in your app.

Querying content from your stack

To get a single entry, you need to specify the content type as well as the ID of the entry.

const Stack = Contentstack.Stack({ "api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment" });
const entry = Stack.ContentType('blog').Entry("entry_uid");
const result = await entry.toJSON().fetch();

Note: We have a method on query for a specific language. For example, consider the following query:

Stack.ContentType('content_type_uid').Query().language('fr-fr').toJSON().find();

It will provide all entries of a content type published on the French locale.

To retrieve multiple entries of a content type, you need to specify the content type uid. You can also specify search parameters to filter results.

const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment" });
const Query = Stack.ContentType('blog').Query();
Query.where("title", "welcome")
.includeSchema()
.includeCount()
.toJSON()
.find()
.then((result) => {
})
.catch((error))=> {
});
Note:
  • Currently, the JavaScript SDK does not support multiple content types referencing in a single query. For more information on how to query entries and assets, refer the Queries section of our Content Delivery API documentation.
  • By default, the limit for response details per request is 100, with the maximum limit set at 250.

Paginating Responses

In a single instance, the Get Multiple Entries query will retrieve only the first 100 items of the specified content type. You can paginate and retrieve the rest of the items in batches using the skip and limit parameters in subsequent requests.

const Stack = Contentstack.Stack({ "api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment" });
let blogQuery = Stack.ContentType('example').Query();
blogQuery.skip(20).limit(20).find()
.then((result) => {
}).catch((error))=> {
});

Querying Assets from your stack

To get a single asset, you need to specify the UID of the asset.

const Stack = Contentstack.Stack({ "api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment" });
const Asset = Stack.Asset("asset_uid");
Asset.fetch()
.then((result) => {
}).catch((error))=> {
});

To retrieve multiple assets. You can also specify search parameters to filter results.

const Stack = Contentstack.Stack({ "api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment" });
const Query = Stack.Asset().Query();
Query
.limit(20)
.toJSON()
.find()
.then(function success(result) {
}, function error(err) {
});

Cache Policies

You can set a cache policy on a stack and/or query object.

Setting a cache policy on a stack

This option allows you to globalize a cache policy. This means the cache policy you set will be applied to all the query objects of the stack.

//Setting a cache policy on a stack
Stack.setCachePolicy(Contentstack.CachePolicy.NETWORK_ELSE_CACHE)
Setting a cache policy on a query object

This option allows you to set/override a cache policy on a specific query object.

// setting a cache policy on a queryobject
Query.setCachePolicy(Contentstack.CachePolicy.CACHE_THEN_NETWORK)

Contentstack

Creates an instance of `Contentstack`.

NameTypeDescription

CachePolicy

Contentstack.CachePolicy

CachePolicy contains different cache policies constants.

Default: Contentstack.CachePolicy.IGNORE_CACHE

Stack

Initialize an instance of ‘Stack’

Returns:
Type
Stack
NameTypeDescription

api_key (required)

string

Stack API key

delivery_token

string

Stack Delivery token.

environment

string

Stack Environment name.

region

ContentstackRegion | string

DB region for Stack. You can choose from five regions namely, NA, EU, Azure NA, Azure EU, and GCP NA.

branch

string

Name of the branch you want to fetch data from

live_preview

object

Live preview configuration.

fetchOptions.debug

boolean

Optional, to enable debug logs set to true.

Default: false

fetchOptions.logHandler

function

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

fetchOptions.agent

HttpProxyAgent

fetchOptions.timeout

number

Set timeout for the request.

fetchOptions.retryLimit

number

The number of retries before failure.

Default: 5

fetchOptions.retryDelay

number

The number of ms to use for operation retries.

Default: 300ms

fetchOptions.retryCondition

function

A function to determine if the error can be retried.

Default: Retry is on status codes 408, 429

fetchOptions.retryDelayOptions.base

number

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

fetchOptions.retryDelayOptions.customBackoff

number

A custom function that accepts a retry count and error and returns the amount of time to delay in milliseconds.

Initialize Stack:

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment' });

To set the European, Azure North American, Azure European, or GCP North America region, refer to the code below:

import Contentstack from 'contentstack';
const Stack = new Contentstack({ 'api_key': "api_key", 'delivery_token': "delivery_token", 'environment': "environment", "region": Contentstack.Region.<<add_your_region>>})

For Setting the Branch for a Region.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment', region: Contentstack.Region.<<add_your_region>>, host: '<<add_your_host_URL>>', branch: 'branch')

Proxy Configuration

const HttpProxyAgent = require("http-proxy-agent");
const proxyAgent = new HttpProxyAgent("http://proxyurl/");
const Stack = Contentstack.Stack({ 
    api_key: 'api_key', 
    delivery_token: 'delivery_token', 
    environment: 'environment',
    fetchOptions: {
       agent: proxyAgent
    }
});

Here are a few examples of how you can add a username and password to HttpProxyAgent.

  • You can pass it in the URL:
var proxyAgent = new HttpsProxyAgent('https://username:password@your-proxy.com');
  • You can set it in the auth option:
var proxyOpts = url.parse('https://your-proxy.com');
proxyOpts.auth = 'username:password';
var proxyAgent = new HttpsProxyAgent(proxyOpts);
  • You can even set the HTTP header manually:
var proxyOpts = url.parse('https://your-proxy.com');
proxyOpts.headers = {
  'Proxy-Authentication': 'Basic ' + new Buffer('username:password').toString('base64')
};
var proxyAgent = new HttpsProxyAgent(proxyOpts);

Plugins

When creating custom plugins, through this request, you can pass the details of your custom plugins. This facilitates their utilization in subsequent requests when retrieving details.

// custom class for plugin
class CrossStackPlugin {
  onRequest (stack, request) {
    // request modifications
    return request
  }
  async onResponse (stack, request, response, data) {
    // response modifications here
    return response
  }
}
const Stack = Contentstack.Stack({
  api_key,
  delivery_token,
  environment,
  plugins: [
    new CrossStackPlugin(),
    new Livepreview()
  ]
});

Stack

Initialize an instance of ‘Stack’
NameTypeDescription

param.api_key (required)

string

Stack API Key.

param.delivery_token (required)

string

Stack Delivery token.

param.environment (required)

string

Stack Environment name.

setProtocol

Sets the protocol for the host
Returns:
Type
Stack
NameTypeDescription

protocol

string

Web Protocol for request (http or https)

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
Stack.setProtocol('https');

setHost

Sets the host of the API server

Returns:
Type
Stack
NameTypeDescription

host

string

Sets the host of the API server

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
Stack.setHost('custom.contentstack.com');

setPort

Sets the port of the host
Returns:
Type
Stack
NameTypeDescription

port

number

Port number of the endpoint

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
Stack.setPort(443);

setCachePolicy

Allows you to set cache policies
Returns:
Type
Stack
NameTypeDescription

key

Contentstack.CachePolicy

Default: Contentstack.CachePolicy.ONLY_NETWORK
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
Stack.setCachePolicy(Contentstack.CachePolicy.IGNORE_CACHE);

setCacheProvider

Sets the Cache Provider's get and set methods used in SDK to cache data.

Returns:
Type
Stack
import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
Stack.setCacheProvider({
  get: function (key, callback) {
    try {
        callback(null, <cache_provider>.get(key));
    } catch(e) {
        callback(e);
    }
  },
  set: function (key, value, callback) {
    try {
        if(key && value) <cache_provider>.set(key, value);
        callback();
    } catch(e) {
        callback(e);
    }
  }
});

getCacheProvider

Returns the currently set object of 'CacheProvider'

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
Stack.getCacheProvider();

Assets

Retrieves all assets of a stack by default. To retrieve a single asset, specify its UID.
Returns:
Type
Assets
NameTypeDescription

uid

string

UID of the asset

To get all Assets from the stack:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.Assets().Query().toJSON().find();

To get a specific Asset from the stack using UID:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.Assets('asset_uid').toJSON().find();

ContentType

Set the content type of which you want to retrieve the entries
Returns:
Type
Stack
NameTypeDescription

content_type_uid

string

UID of the existing content type

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.ContentType('content_type_uid').Query().toJSON().find();

getContentTypes

This method returns comprehensive information of all the content types of a particular stack in your account.

Returns:
Type
Promise
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
Const result = await Stack.getContentTypes({"include_global_field_schema": true});

getLastActivities

The getLastActivities retrieves all the ContentTypes whose last activity updated.

Returns:
Type
Promise
import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.getLastActivities().toJSON().fetch();

Taxonomies

Set the base URL to the taxonomies endpoint.

Example:

import Contentstack from 'contentstack';
const stack = Contentstack.stack('api_key', 'delivery_token', 'environment');
let data;
stack
.Taxonomies()
.where("taxonomies.taxonomy_uid", "term_uid")
.toJSON()
.find()
.then(response => {
  // the response
  data = response;
})

Query

An initializer is responsible for creating Query object.Provides support for all search queries
Returns:
Type
Query

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.ContentType('content_type_uid').Query().toJSON().find();

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.Assets().Query().toJSON().find();

imageTransform

Performs transformations on images of mentioned url based on transformation parameters

Returns:
Type
string
NameTypeDescription

url

string

Image url on which transformations need to be applied.

params

object

Object with transformation parameters

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
Stack.imageTransform(imageURL, {height: 100, width: 200, disable: "upscale"});
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
Stack.imageTransform(imageURL, {crop: "150,100"});
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
Stack.imageTransform(imageURL, {format: "png", crop: "150,100"});

sync

Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates
Returns:
Type
Promise
NameTypeDescription

param.init

boolean

initializing sync

param.locale

string

initializing sync with entries of a specific locale

param.start_date

string

Default: initializing sync with entries published after a specific date

param.content_type_uid

string

initializing sync with entries of a specific content type

param.type

string

Use the type parameter to get a specific type of content.Supports 'asset_published', 'entry_published', 'asset_unpublished', 'entry_unpublished', 'asset_deleted', 'entry_deleted', 'content_type_deleted'

param.pagination_token

string

Fetching the next batch of entries using pagination token

param.sync_token

string

Performing subsequent sync after initial sync

For initializing sync:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.sync({'init': true});

For initializing sync with entries of a specific locale:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.sync({'init': true, 'locale': 'en-us'});

For initializing sync with entries published after a specific date:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.sync({'init': true, 'start_date': '2018-10-22'});

For initializing sync with entries of a specific content type:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.sync({'init': true, 'content_type_uid': 'session'});

For initializing sync with specific type:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.sync({'init': true, 'type': 'entry_published'});

For fetching the next batch of entries using pagination token:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.sync({'pagination_token': '<page_token>'});

For performing subsequent sync after initial sync:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({"api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment"});
const result = await Stack.sync({'sync_token': '<sync_token>'}) 

Assets

Creates an instance of `Assets`.

Retrieves all assets of a stack by default. To retrieve a single asset, specify its UID.

NameTypeDescription

uid

string

UID of asset you want to retrieve

addParam

Returns:
Type
Assets
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.Assets('asset_uid').addParam('include_dimension', 'true').toJSON().fetch();

toJSON

Converts your response into plain JavasScript object<.p>

Returns:
Type
Assets|Entry|Query
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().toJSON().find();
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.Assets().Query().toJSON().find();
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').toJSON().fetch();
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.Assets('asset_uid').toJSON().fetch();

fetch

Fetches a particular asset based on the provided asset UID.
Returns:
Type
Promise
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.Assets('asset_uid').addParam('include_dimension', 'true').toJSON().fetch();

where

The where() method retrieves the assets from the stack using any other field UID of the assets.

Returns:
Type
Assets
NameTypeDescription

field_name (required)

String

Field UID of the Asset

value (required)

String

Value of the Asset

Example:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.Assets().Query().where('field_name', "value").toJSON().find()

Entry

An initializer is responsible for creating Entry object.
NameTypeDescription

uid (required)

string

Uid of the entry

language

Sets the language code of which you want to retrieve data.
Returns:
Type
Entry
NameTypeDescription

language_code

string

language code. e.g. 'en-us', 'ja-jp', etc.

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').language('language_code').toJSON().fetch();

addParam

Includes query parameters in your queries.

Returns:
Type
Entry
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').addParam('include_count', 'true').toJSON().fetch();

addQuery

Adds query to Entry object

Returns:
Type
Entry
NameTypeDescription

key

string

Key of the query

value

any

Value of the query

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').addQuery('include_content_type', true).toJSON().fetch();

only

Displays values of only the specified fields of entries or assets in the response
Returns:
Type
Entry
NameTypeDescription

values

string|array

Field UID of content type

The only function with field_uid will include the data of only the specified fields for each entry and exclude the data of all other fields.

import Contentstack from 'contentstack'; 
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').only('title').toJSON().fetch();

The only function with an array of field_uids will include multiple fields for each entry and exclude the data of all other fields.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').only(['title', 'description']).toJSON().fetch();

In only, we have the only with a reference parameter, where you need to enter the UID of the reference field in place of "reference_field_uid", and the second parameter to include the data of only the specified field_uid for each entry and exclude the data of all other fields.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').includeReference('reference_field_uid').only('reference_field_uid','title').toJSON().fetch();

In only, we have the only with a reference parameter with an array, where you need to enter the UID of the reference field in place of "reference_field_uid", and the second parameter with an array of fields to include the data of only the specified array of field_uids for each entry and exclude the data of all other fields.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').includeReference('reference_field_uid').only('reference_field_uid',['title', 'description']).toJSON().fetch();

except

Displays all data of an entries or assets excluding the data of the specified fields.
Returns:
Type
Entry
NameTypeDescription

values

string|array

Field UID of content type

The except function with field_uid will exclude the data of only the specified fields for each entry and includes the data of all other fields.

import Contentstack from 'contentstack'; 
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').except('title').toJSON().fetch();

The except function with an array of field_uids will except multiple fields for each entry and include the data of all other fields.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').except(['title', 'description']).toJSON().fetch();

In except, we have the only with a reference parameter, where you need to enter the UID of the reference field in place of "reference_field_uid", and the second parameter to except the data of only the specified field_uid for each entry and include the data of all other fields.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').includeReference('reference_field_uid').except('reference_field_uid','title').toJSON().fetch();

In except, we have the only with a reference parameter with an array, where you need to enter the UID of the reference field in place of "reference_field_uid", and the second parameter with an array of fields to except the data of only the specified array of field_uids for each entry and include the data of all other fields.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').includeReference('reference_field_uid').except('reference_field_uid',['title', 'description']).toJSON().fetch();

includeReference

Fetches the entire content of referenced entry.

Returns:
Type
Entry
NameTypeDescription

value

string|array

Field UID of content type

Include Reference with reference_field_uids as array:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').includeReference(['reference_field_uid','other_reference_field_uid']).toJSON().fetch();

Include Reference with reference_field_uids and its children reference

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').includeReference(['reference_field_uid', 'reference_field_uid.child_reference_field_uid']).toJSON().fetch();

Include Reference with reference_field_uid:

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').includeReference('reference_field_uid').toJSON().fetch();

includeReferenceContentTypeUID

This method also includes the content type UIDs of the referenced entries returned in the response.

Returns:
Type
Entry
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').includeReferenceContentTypeUID().toJSON().fetch();

includeEmbeddedItems

Include Embedded Objects (Entries and Assets) along with entry/entries details.
Returns:
Type
Entry
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').includeEmbeddedItems().toJSON().fetch();

includeContentType

Include the details of the content type along with the entry/entries details.

Returns:
Type
Entry
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').includeContentType().toJSON().fetch();

Your response should look like this:

 [
  [
    {
      "uid": "blt3458ba16457349d2",
      "locale": "en-us",
      "_in_progress": false,
      "created_at": "2024-09-24T21:37:12.148Z",
      "created_by": "bltcd145d6b20c55b33",
      "title": "Test1",
      "updated_at": "2024-11-11T23:56:55.437Z",
      "updated_by": "bltcd145d6b20c55b33",
      "publish_details": {
        "time": "2024-11-11T23:56:59.408Z",
        "user": "bltcd145d6b20c55b33",
        "environment": "blt47ebc22ff5bb18d9",
        "locale": "en-us"
      }
    }
  ],
  {
    "title": "ct1",
    "description": "",
    "schema": [
      {
        "data_type": "text",
        "display_name": "Title",
        "field_metadata": { "_default": true, "version": 3 },
        "mandatory": true,
        "uid": "title",
        "unique": true,
        "multiple": false,
        "non_localizable": false
      }
    ],
    "uid": "ct1",
    "created_at": "2024-09-24T21:23:33.625Z",
    "updated_at": "2024-09-24T21:24:42.841Z",
    "inbuilt_class": false,
    "_version": 2
  }
]

includeBranch

Include the Branch for publish content.

Returns:
Type
Entry
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').includeBranch().toJSON().fetch();

includeFallback

Include the fallback locale publish content, if specified locale content is not publish.

Returns:
Type
Entry
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
Stack.ContentType('content_type_uid;).Entry('entry_uid').includeFallback().fetch();

fetch

Fetches a particular entry based on the provided entry UID.

Returns:
Type
Promise
NameTypeDescription

param

object

Fetch options to fetch particular entry

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').language('language_code').toJSON().fetch();

Variants

Variants are different versions of content designed to meet specific needs or target audiences. This feature allows content editors to create multiple variations of a single entry, each customized for a particular variant group or purpose.

When Personalize creates a variant in the CMS, it assigns a "Variant Alias" to identify that specific variant. When fetching entry variants using the Delivery API, you can pass variant aliases in place of variant UIDs in the x-cs-variant-uid header.

Returns:
Type
Promise

Single Variant: This method retrieves the details of a specific entry variant.

Example:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').variants('variant_uid/variant_alias').toJSON().fetch()

Layering Variants: This method retrieves the details of entry variants based on the applied query

Example:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').variants(['variant_uid1/variant_alias1','variant_uid2/variant_alias2']).toJSON().fetch()

Note:All methods in the Query section are applicable for variants filtering as well.

Add Query in Variants: This method adds a query to the entry object

Example:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Entry('entry_uid').variants('variant_uid/variant_alias').addQuery('include_content_type', true).toJSON().fetch()

Taxonomy

Taxonomy helps you categorize pieces of content within your stack to facilitate easy navigation and retrieval of information.

Note: All methods in the Query section are applicable for taxonomy-based filtering as well.

equalAndBelow

The equalAndBelow method retrieves all entries for a specific taxonomy that match a specific term and all its descendant terms, requiring only the target term.

Note: This query is applicable for the stack.Taxonomies() and stack.ContentType('uid').Query() methods.

Returns:
Type
Query
NameTypeDescription

key (required)

string

UID of the taxonomy field, specified as "taxonomies.<taxonomy_uid>"

value (required)

string

UID of the term to match or compare

levels

int

Depth level till which terms will be matched

Example:

let data;
stack
.ContentType('ct_uid')
.Query()
.equalAndBelow("taxonomies.taxonomy_uid", "term_uid", 3)
.toJSON()
.find()
.then(response => {
  // the response
  data = response;
})

below

The below method retrieves all entries for a specific taxonomy that match all of their descendant terms by specifying only the target term and a specific level.

Note: If you don't specify the level, the default behavior is to retrieve terms up to level 10.

Returns:
Type
Query
NameTypeDescription

key (required)

string

UID of the taxonomy field, specified as "taxonomies.<taxonomy_uid>"

value (required)

string

UID of the term to match or compare

levels

int

Depth level till which terms will be matched

Example:

let data;
stack
.ContentType('ct_uid')
.Query()
.below("taxonomies.taxonomy_uid", "term_uid", 3)
.toJSON()
.find()
.then(response => {
  // the response
  data = response;
})

equalAndAbove

The equalAndAbove method retrieves all entries for a specific taxonomy that match a specific term and all its ancestor terms, requiring only the target term and a specified level.

Note: If you don't specify the level, the default behavior is to retrieve terms up to level 10.

Returns:
Type
Query
NameTypeDescription

key (required)

string

UID of the taxonomy field, specified as "taxonomies.<taxonomy_uid>"

value (required)

string

UID of the term to match or compare

levels

int

Depth level till which terms will be matched

Example:

let data;
stack
.Taxonomies()
.equalAndAbove("taxonomies.taxonomy_uid", "term_uid", 3)
.toJSON()
.find()
.then(response => {
  // the response
  data = response;
})

above

The above method retrieves all entries for a specific taxonomy that match only the parent term(s) of a specified target term, excluding the target term itself and a specified level.

Note: If you don't specify the level, the default behavior is to retrieve terms up to level 10.

Returns:
Type
Query
NameTypeDescription

key (required)

string

UID of the taxonomy field, specified as "taxonomies.<taxonomy_uid>"

value (required)

string

UID of the term to match or compare

levels

int

Depth level till which terms will be matched

Example:

let data;
stack
.ContentType('ct_uid')
.Query()
.above("taxonomies.taxonomy_uid", "term_uid", 3)
.toJSON()
.find()
.then(response => {
  // the response
  data = response;
})

Query

An initializer is responsible for creating Query object. Provides support for all search queries

addParam

Includes query parameters in your queries.

Returns:
Type
Query
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().addParam('include_count', 'true').toJSON().find();

where

Retrieve entries in which a specific field satisfies the value provided

Returns:
Type
Query
NameTypeDescription

key

string

UID of the field

value

any

Value used to match or compare

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().where('title', 'some random title').toJSON().find();

notEqualTo

Retrieves entries in which the value for a field does not match the provided value.

Returns:
Type
Query
NameTypeDescription

key

string

UID of the field

value

any

Value used to match or compare

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().notEqualTo('title', 'some random title').toJSON().find();

containedIn

Retrieve entries in which the value of a field matches with any of the provided array of values

Returns:
Type
Query
NameTypeDescription

key

string

UID of the field

value

array

Array of values that are to be used to match or compare

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().containedIn('title', ['Demo', 'Welcome']).toJSON().find();

notContainedIn

Retrieve entries in which the value of a field does not match with any of the provided array of values.

Returns:
Type
Query
NameTypeDescription

key

string

UID of the field

value

array

Array of values that are to be used to match or compare

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().notContainedIn('title', ['Demo', 'Welcome']).toJSON().find();

and

Retrieve entries that satisfy all the provided conditions.

Returns:
Type
Query
NameTypeDescription

queries

array

array of Query objects or raw queries

and with Query instances:

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const Query1 = Stack.ContentType('content_type_1').Query().where('title', 'demo');
const Query2 = Stack.ContentType('content_type_1').Query().lessThan('age', 30);
const result = await Stack.ContentType('content_type_uid').Query().and(Query1, Query2).toJSON().find();

and with raw queries:

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const Query1 = Stack.ContentType('content_type_1').Query().where('title', 'demo').getQuery();
const Query2 = Stack.ContentType('content_type_1').Query().lessThan('age', 30).getQuery();
const result = await Stack.ContentType('content_type_uid').Query().and(Query1, Query2).toJSON().find();

or

Retrieves entries that satisfy at least one of the given conditions

Returns:
Type
Query
NameTypeDescription

queries

array

array of Query objects or raw queries

or with Query instances:

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const Query1 = Stack.ContentType('content_type_1').Query().where('title', 'demo');
const Query2 = Stack.ContentType('content_type_1').Query().lessThan('age', 30);
const result = await Stack.ContentType('content_type_uid').Query().or(Query1, Query2).toJSON().find();

or with raw queries:

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const Query1 = Stack.ContentType('content_type_1').Query().where('title', 'demo').getQuery();
const Query2 = Stack.ContentType('content_type_1').Query().lessThan('age', 30).getQuery();
const result = await Stack.ContentType('content_type_uid').Query().or(Query1, Query2).toJSON().find();

lessThan

Retrieves entries in which the value of a field is lesser than the provided value

Returns:
Type
Query
NameTypeDescription

key

string

UID of the field

value

any

Value used to match or compare

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().lessThan('age', 20).toJSON().find();

lessThanOrEqualTo

Retrieves entries in which the value of a field is lesser than or equal to the provided value.

Returns:
Type
Query
NameTypeDescription

key

string

UID of the field

value

any

Value used to match or compare

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().lessThanOrEqualTo('age', 20).toJSON().find();

greaterThan

Retrieves entries in which the value for a field is greater than the provided value.

Returns:
Type
Query
NameTypeDescription

key

string

UID of the field

value

any

Value used to match or compare

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().greaterThan('age', 20).toJSON().find();

greaterThanOrEqualTo

Retrieves entries in which the value for a field is greater than or equal to the provided value.

Returns:
Type
Query
NameTypeDescription

key

string

UID of the field

value

any

Value used to match or compare

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().greaterThanOrEqualTo('age', 20).toJSON().find();

limit

Returns a specific number of entries based on the set limit

Returns:
Type
Query
NameTypeDescription

limit

number

maximum number of entries to be returned

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().limit(20).toJSON().find();

skip

Skips at specific number of entries.

Returns:
Type
Query
NameTypeDescription

skip

number

number of entries to be skipped

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().skip(20).toJSON().find();

ascending

Sort fetched entries in the ascending order with respect to a specific field.

Returns:
Type
Query
NameTypeDescription

key

string

field uid based on which the ordering will be done

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().ascending('field_uid').toJSON().find();

descending

Sort fetched entries in the descending order with respect to a specific field

Returns:
Type
Query
NameTypeDescription

key

string

field uid based on which the ordering will be done

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().descending('field_uid').toJSON().find();

exists

Retrieve entries if value of the field, mentioned in the condition, exists.

Returns:
Type
Query
NameTypeDescription

key

string

UID of the field

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().exists('field_uid').toJSON().find();

notExists

Retrieve entries if value of the field, mentioned in the condition, does not exists.

Returns:
Type
Query
NameTypeDescription

key

string

UID of the field

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().notExists('field_uid').toJSON().find();

only

Displays values of only the specified fields of entries or assets in the response

Returns:
Type
Query
NameTypeDescription

values

string|array

Field UID of content type

The only function with field_uid will include the data of only the specified fields for each entry and exclude the data of all other fields.

import Contentstack from 'contentstack'; 
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().only('title').toJSON().find();

The only function with an array of field_uids will include multiple fields for each entry and exclude the data of all other fields.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().only(['title', 'description']).toJSON().find();

In only, we have the only with a reference parameter, where you need to enter the UID of the reference field in place of "reference_field_uid", and the second parameter to include the data of only the specified field_uid for each entry and exclude the data of all other fields.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().includeReference('reference_field_uid').only('reference_field_uid','title').toJSON().find();

In only, we have the only with a reference parameter with an array, where you need to enter the UID of the reference field in place of "reference_field_uid", and the second parameter with an array of fields to include the data of only the specified array of field_uids for each entry and exclude the data of all other fields.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().includeReference('reference_field_uid').only('reference_field_uid',['title', 'description']).toJSON().find();

except

Displays all data of an entries or assets excluding the data of the specified fields.

Returns:
Type
Query
NameTypeDescription

values

string|array

Field UID of content type

The except function with field_uid will exclude the data of only the specified fields for each entry and includes the data of all other fields.

import Contentstack from 'contentstack'; 
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().except('title').toJSON().find();

The except function with an array of field_uids will except multiple fields for each entry and include the data of all other fields.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().except(['title', 'description']).toJSON().find();

In except, we have the only with a reference parameter, where you need to enter the UID of the reference field in place of "reference_field_uid", and the second parameter to except the data of only the specified field_uid for each entry and include the data of all other fields.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().includeReference('reference_field_uid').except('reference_field_uid','title').toJSON().find();

In except, we have the only with a reference parameter with an array, where you need to enter the UID of the reference field in place of "reference_field_uid", and the second parameter with an array of fields to except the data of only the specified array of field_uids for each entry and include the data of all other fields.

import Contentstack from &'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().includeReference('reference_field_uid').except('reference_field_uid',['title', 'description']).toJSON().find();

regex

Retrieve entries that match the provided regular expressions

Returns:
Type
Query
NameTypeDescription

key

string

uid of the field

value

any

value used to match or compare

options

any

match or compare value in entry

regex without options

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().regex('title', '^Demo').toJSON().find();

regex with options

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().regex('title', '^Demo', 'i').toJSON().find();

tags

Retrieves entries based on the provided tags.

Returns:
Type
Query
NameTypeDescription

values

array

array of tags

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().tags(['technology', 'business']).toJSON().find();

includeReference

Fetches the entire content of referenced entry.

Returns:
Type
Query
NameTypeDescription

value

string|array

Field UID of content type

Include Reference with reference_field_uids as array:

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().includeReference(['reference_field_uid','other_reference_field_uid']).toJSON().find();

Include Reference with reference_field_uids and its children reference

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().includeReference(['reference_field_uid', 'reference_field_uid.child_reference_field_uid']).toJSON().find();

Include Reference with reference_field_uid:

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().includeReference('reference_field_uid').toJSON().find();

referenceIn

Retrieve entries based on raw queries.

Returns:
Type
Query
NameTypeDescription

fieldUid

string

Reference field Uid

query

object

RAW (JSON) queries

referenceIn with Query instances

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const Query1 = Stack.ContentType('content_type_1').Query().where('title', 'Demo');
const result = await Stack.ContentType('content_type_uid').Query().referenceIn('brand', Query1).toJSON().find();

referenceIn with raw queries:

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().referenceIn('brand', {'title': 'Demo'}).toJSON().find();

referenceNotIn

Retrieve entries based on raw queries.

Returns:
Type
Query
NameTypeDescription

fieldUid

string

Reference field Uid

query

object

RAW (JSON) queries

referenceNotIn with Query instances:

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const Query1 = Stack.ContentType('content_type_1').Query().where('title', 'Demo');
const result = await Stack.ContentType('content_type_uid').Query().referenceNotIn('brand', Query1).toJSON().find();

referenceNotIn with raw queries:

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().referenceNotIn('brand', {'title': 'Demo'}).toJSON().find();

includeReferenceContentTypeUID

This method also includes the content type UIDs of the referenced entries returned in the response.

Returns:
Type
Query
import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().includeReferenceContentTypeUID().toJSON().find();

includeCount

Includes the total number of entries returned in the response.

Returns:
Type
Query
import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().includeCount().toJSON().find();

includeContentType

Include the details of the content type along with the entry/entries details.

Returns:
Type
Query
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().includeContentType().toJSON().find();

Your response should look like this:

[
  [
    {
      "uid": "blt3458ba16457349d2",
      "locale": "en-us",
      "_in_progress": false,
      "created_at": "2024-09-24T21:37:12.148Z",
      "created_by": "bltcd145d6b20c55b33",
      "title": "Test1",
      "updated_at": "2024-11-11T23:56:55.437Z",
      "updated_by": "bltcd145d6b20c55b33",
      "publish_details": {
        "time": "2024-11-11T23:56:59.408Z",
        "user": "bltcd145d6b20c55b33",
        "environment": "blt47ebc22ff5bb18d9",
        "locale": "en-us"
      }
    }
  ],
  {
    "title": "ct1",
    "description": "",
    "schema": [
      {
        "data_type": "text",
        "display_name": "Title",
        "field_metadata": { "_default": true, "version": 3 },
        "mandatory": true,
        "uid": "title",
        "unique": true,
        "multiple": false,
        "non_localizable": false
      }
    ],
    "uid": "ct1",
    "created_at": "2024-09-24T21:23:33.625Z",
    "updated_at": "2024-09-24T21:24:42.841Z",
    "inbuilt_class": false,
    "_version": 2
  }
]

includeBranch

Include the Branch for publish content.

Returns:
Type
Query
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().includeBranch().toJSON().find();

includeEmbeddedItems

Include Embedded Objects (Entries and Assets) along with entry/entries details.

Returns:
Type
Query
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().includeEmbeddedItems().toJSON().find();

includeFallback

Include the fallback locale publish content, if specified locale content is not publish.

Returns:
Type
Entry
import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
Stack.ContentType('content_type_uid;).Query().includeFallback().fetch();

query

Retrieve entries based on raw queries.

Returns:
Type
Query
NameTypeDescription

query

object

RAW (JSON) queries

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().query({'brand': {'$nin_query': {'title': 'Apple Inc.'}}}).toJSON().find();

addQuery

Adds query to Entry object.

Returns:
Type
Query
NameTypeDescription

key

string

Key of the query

value

any

Value of the query

import Contentstack from 'contentstack'
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().addQuery('include_content_type', true).toJSON().find();

getQuery

Returns the raw (JSON) query based on the filters applied on Query object.

Returns:
Type
Query
import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const rawQuery = await Stack.ContentType('content_type_uid').Query().where('title', 'Demo').getQuery();

language

Sets the language code of which you want to retrieve data.

Returns:
Type
Query
NameTypeDescription

language_code

string

language code. e.g. 'en-us', 'ja-jp', etc.

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().language('language_code').toJSON().find();

find

Retrieves entries that satisfied the specified query.

Returns:
Type
Promise
NameTypeDescription

param

object

Fetch options to fetch particular query

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().toJSON().find();

findOne

Retrieves entries that satisfied the specified query.

Returns:
Type
Promise
NameTypeDescription

param

object

Fetch options to fetch particular query

import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().toJSON().findOne();

count

Returns the total number of entries

Returns:
Type
Query
import Contentstack from 'contentstack';
const Stack = Contentstack.Stack({'api_key': 'api_key', 'delivery_token': 'delivery_token', 'environment': 'environment'});
const result = await Stack.ContentType('content_type_uid').Query().count().toJSON().find();

equalAndBelow

The equalAndBelow method retrieves all entries for a specific taxonomy that match a specific term and all its descendant terms, requiring only the target term.

Note: This query is applicable for the stack.Taxonomies() and stack.ContentType('uid').Query() methods.

Returns:
Type
Query
NameTypeDescription

key (required)

string

UID of the taxonomy field, specified as taxonomies.<taxonomy_uid>

value (required)

string

UID of the term to match or compare

levels

int

Depth level till which terms will be matched

Example:

let data;
stack
.ContentType('ct_uid')
.Query()
.equalAndBelow("taxonomies.taxonomy_uid", "term_uid", 3)
.toJSON()
.find()
.then(response => {
  // the response
  data = response;
})

below

The below method retrieves all entries for a specific taxonomy that match all of their descendant terms by specifying only the target term and a specific level.

Note: If you don't specify the level, the default behavior is to retrieve terms up to level 10.

Returns:
Type
Query
NameTypeDescription

key (required)

string

UID of the taxonomy field, specified as taxonomies.<taxonomy_uid>

value (required)

string

UID of the term to match or compare

levels

int

Depth level till which terms will be matched

Example:

let data;
stack
.ContentType('ct_uid')
.Query()
.below("taxonomies.taxonomy_uid", "term_uid", 3)
.toJSON()
.find()
.then(response => {
  // the response
  data = response;
})

equalAndAbove

The equalAndAbove method retrieves all entries for a specific taxonomy that match a specific term and all its ancestor terms, requiring only the target term and a specified level.

Note: If you don't specify the level, the default behavior is to retrieve terms up to level 10.

Returns:
Type
Query
NameTypeDescription

key (required)

string

UID of the taxonomy field, specified as taxonomies.<taxonomy_uid>

value (required)

string

UID of the term to match or compare

levels

int

Depth level till which terms will be matched

Example:

let data;
stack
.Taxonomies()
.equalAndAbove("taxonomies.taxonomy_uid", "term_uid", 3)
.toJSON()
.find()
.then(response => {
  // the response
  data = response;
})

above

The above method retrieves all entries for a specific taxonomy that match only the parent term(s) of a specified target term, excluding the target term itself and a specified level.

Note: If you don't specify the level, the default behavior is to retrieve terms up to level 10.

Returns:
Type
Query
NameTypeDescription

key (required)

string

UID of the taxonomy field, specified as taxonomies.<taxonomy_uid>

value (required)

string

UID of the term to match or compare

levels

int

Depth level till which terms will be matched

Example:

let data;
stack
.ContentType('ct_uid')
.Query()
.above("taxonomies.taxonomy_uid", "term_uid", 3)
.toJSON()
.find()
.then(response => {
  // the response
  data = response;
})