Stack

View as Markdown

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
NameTypeDescription
protocolstring

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

NameTypeDescription
hoststring

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
NameTypeDescription
portnumber

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
NameTypeDescription
keyContentstack.CachePolicyDefault: 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.

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.
NameTypeDescription
uidstring

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
NameTypeDescription
content_type_uidstring
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.

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.

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

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

NameTypeDescription
urlstring

Image url on which transformations need to be applied.

paramsobject

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
NameTypeDescription
param.initboolean
initializing sync
param.localestring
initializing sync with entries of a specific locale
param.start_datestringDefault: initializing sync with entries published after a specific date
param.content_type_uidstring

initializing sync with entries of a specific content type

param.typestring

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_tokenstring

Fetching the next batch of entries using pagination token

param.sync_tokenstring

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>'})