Stack
Stack
| Name | Type | Description |
|---|---|---|
| param.api_key (required) | string | Stack API Key. |
| param.delivery_token (required) | string | Stack Delivery token. |
| param.environment (required) | string | Stack Environment name. |
setProtocol
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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.
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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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.
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
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
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
| Name | Type | Description |
|---|---|---|
| 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
| Name | Type | Description |
|---|---|---|
| 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>'})