Global

Members

(constant) CachePolicy

CachePolicy contains different cache policies constants.
Example
Contentstack.CachePolicy.IGNORE_CACHE
Contentstack.CachePolicy.ONLY_NETWORK
Contentstack.CachePolicy.CACHE_ELSE_NETWORK
Contentstack.CachePolicy.NETWORK_ELSE_CACHE
Contentstack.CachePolicy.CACHE_THEN_NETWORK

Methods

Contentstack()

Creates an instance of `Contentstack`.

Stack() → {Stack}

Initialize "Built.io Contentstack" Stack javascript-SDK instance
Example
var Stack = Contentstack.Stack('api_key', 'access_token', 'environment');
                 OR
var Stack = Contentstack.Stack({
     'api_key':'bltsomethingapikey',
     'access_token':'bltsomethongtoken',
     'environment':'environment_name'
  });

setPort(port)

Sets the port of the host.
Parameters:
Name Description
port Port Number

setProtocol(protocol)

Sets the protocol of the host.
Parameters:
Name Description
protocol http/https protocol

setHost(host)

Sets the host of the API server.
Parameters:
Name Description
host valid ip or host

setCachePolicy(keyopt) → {Stack}

setCachePolicy which contains different cache policies.
Parameters:
Name Attributes Default Description
key <optional>
ONLY_NETWORK Cache policy to be applied on Stack or Query.
Example
Stack.setCachePolicy(Contentstack.CachePolicy.IGNORE_CACHE)
Stack.setCachePolicy(Contentstack.CachePolicy.ONLY_NETWORK)
Stack.setCachePolicy(Contentstack.CachePolicy.CACHE_ELSE_NETWORK)
Stack.setCachePolicy(Contentstack.CachePolicy.NETWORK_ELSE_CACHE)
Stack.setCachePolicy(Contentstack.CachePolicy.CACHE_THEN_NETWORK)

setCacheProvider() → {Stack}

Set 'Cache Provider' object.
Example
Stack
     .setCacheProvider({
         get: function (key, callback) {
             // custom logic
         },
         set: function (key, value, callback) {
             // custom logic
         }
     });

getCacheProvider() → {Object}

Returns currently set CacheProvider object.
Example
Stack.getCacheProvider();

ContentType(content_type_uidopt) → {Stack}

Set "ContentType" from the Stack from where you want to retrive the entries.
Parameters:
Name Attributes Description
content_type_uid <optional>
uid of the existing contenttype

Entry(uid) → {Entry}

Set the Entry Uid which you want to retrive from the Contenttype specified.
Parameters:
Name Description
uid entry_uid
Example
ContentType('blog').Entry('blt1234567890abcef')

Assets(uid) → {Assets}

Set the Asset Uid which you want to retrive the Asset.
Parameters:
Name Description
uid asset_uid
Example
Stack.Assets('blt1234567890abcef').fetch

Query() → {Query}

Query instance to provide support for all search queries.
Example
ContentType('blog').Query()

imageTransform(url, params) → {string}

Transforms provided image url based on transformation parameters.
Parameters:
Name Description
url Url on which transformations to be applied.
params Transformation parameters
Examples
Stack.imageTransform(imageURL, {height: 100, width: 200, disable: "upscale"});
Stack.imageTransform(imageURL, {crop: "150,100"});
Stack.imageTransform(imageURL, {format: "png", crop: "150,100"});

only(keyopt, values) → {Asset}

This method is use to show the selected fields of the assets in resultset.
Parameters:
Name Attributes Default Description
key <optional>
BASE single field in asset
values array of fields to be show in resultset
Examples

.only with field uid

Assets().only('title')

.only with field uid

Assets().only('BASE','title')

.only with field uids(array)

Assets().only(['title','description'])

toJSON() → {Object}

This method is used to convert the result in to plain javascript object.
Example
assetQuery
     .toJSON()
     .then(function (result) {
         let value = result.get(field_uid)
      },function (error) {
         // error function
     })

AddParam()

This method includes query parameter in query.
Example
Stack.Assets('bltsomething123').addParam('include_dimension', 'true').fetch()

fetch()

fetch asset obhect of requested Asset uid of defined query if present.
Example
Stack.Assets('bltsomething123').fetch()

only(keyopt, values) → {Entry}

This method is use to show the selected fields of the entries in resultset.
Parameters:
Name Attributes Default Description
key <optional>
BASE reference field in the entry/single field in entry
values array of fields to be show in resultset
Examples

.only with field uid

blogEntry.only('title')

.only with field uid

blogEntry.only('BASE','title')

.only with field uids(array)

blogEntry.only(['title','description'])

.only with reference_field_uid and field uid

blogEntry.includeReference('category').only('category','title')

.only with reference_field_uid and field uids(array)

blogEntry.includeReference('category').only('category', ['title', 'description'])

except(keyopt, values) → {Entry}

This method is use to hide the selected fields of the entries in resultset.
Parameters:
Name Attributes Default Description
key <optional>
BASE reference field in the entry/single field in entry
values array of fields to be show in resultset
Examples

.except with field uid

blogEntry.except('title')

.except with field uid

blogEntry.except('BASE','title')

.except with field uids(array)

blogEntry.except(['title','description'])

.except with reference_field_uid and field uid

blogEntry.includeReference('category').except('category','title')

.except with reference_field_uid and field uids(array)

blogEntry.includeReference('category').except('category', ['title', 'description'])

includeReference() → {Entry}

This method is use to include referenced entries from the other Contenttype.
Examples

.includeReference with reference_field_uids as array

blogEntry.includeReference(['category', 'author'])

.includeReference with reference_field_uids

blogEntry.includeReference('category', 'author')

language(language_code) → {Entry}

This method is used set language code, which language's data to be retrieve.
Parameters:
Name Description
language_code language code. e.g. 'en-us', 'ja-jp', etc.
Example
blogEntry.language('en-us')

addQuery(key, value) → {Entry}

This method is used to add query to Entry object.
Parameters:
Name Description
key key of the query
value value of the query
Example
blogEntry.addQuery('include_schema',true)

includeSchema() → {Entry}

This method is used to include the schema of the current contenttype in result set along with the entry/entries.
Deprecated:
  • since verion 3.3.0
Example
blogEntry.includeSchema()

includeContentType() → {Entry}

This method is used to include the current contenttype in result set along with the entry/entries.
Example
blogEntry.includeContentType()

includeOwner() → {Entry}

This method is used to include the owner of the entry/entries in resultset.
Example
blogEntry.includeOwner()

toJSON() → {Object}

This method is used to convert the result in to plain javascript object.
Example
blogEntry
     .toJSON()
     .then(function (result) {
         let value = result.get(field_uid)
      },function (error) {
         // error function
     })

AddParam()

This method includes query parameter in query.
Example
blogQuery.addParam('include_count', 'true').fetch()

fetch()

fetch entry of requested content_type of defined query if present.
Example
blogEntry.fetch()

lessThan(key, value) → {Query}

This method provides only the entries with values less than the specified value for a field.
Parameters:
Name Description
key uid of the field that is to be taken into consideration
value The value used to match or compare
Example
blogQuery.lessThan('created_at','2015-06-22')

lessThanOrEqualTo(key, value) → {Query}

This method provides only the entries with values less than or equal to the specified value for a field.
Parameters:
Name Description
key uid of the field that is to be taken into consideration
value The value used to match or compare
Example
blogQuery.lessThanOrEqualTo('created_at','2015-03-12')

greaterThan(key, value) → {Query}

This method provides only the entries with values greater than the specified value for a field.
Parameters:
Name Description
key uid of the field that is to be taken into consideration
value The value used to match or compare
Example
blogQuery.greaterThan('created_at','2015-03-12')

greaterThanOrEqualTo(key, value) → {Query}

This method provides only the entries with values greater than or equal to the specified value for a field.
Parameters:
Name Description
key uid of the field that is to be taken into consideration
value The value used to match or compare
Example
blogQuery.greaterThanOrEqualTo('created_at', '2015-06-22')

notEqualTo(key, value) → {Query}

This method provides only the entries with values not equal to the specified value for a field.
Parameters:
Name Description
key uid of the field that is to be taken into consideration
value The value used to match or compare
Example
blogQuery.notEqualTo('title','Demo')

containedIn(key, value) → {Query}

This method provides only the entries with values matching the specified values for a field.
Parameters:
Name Description
key uid of the field that is to be taken into consideration
value An array of values that are to be used to match or compare
Example
blogQuery.containedIn('title', ['Demo', 'Welcome'])

notContainedIn(key, value) → {Query}

This method provides only the entries that do not contain values matching the specified values for a field.
Parameters:
Name Description
key uid of the field that is to be taken into consideration
value An array of values that are to be used to match or compare
Example
blogQuery.notContainedIn('title', ['Demo', 'Welcome'])

exists(key) → {Query}

This method provides only the entries that contains the field matching the specified field uid.
Parameters:
Name Description
key uid of the field that is to be taken into consideration
Example
blogQuery.exists('featured')

notExists(key) → {Query}

This method provides only the entries that do not contain the field matching the specified field uid.
Parameters:
Name Description
key uid of the field that is to be taken into consideration
Example
blogQuery.notExists('featured')

ascending(key) → {Query}

This parameter sorts the provided entries in the ascending order on the basis of the specified field.
Parameters:
Name Description
key field uid based on which the ordering should be done
Example
blogQuery.ascending('created_at')

descending(key) → {Query}

This method sorts the provided entries in the descending order on the basis of the specified field.
Parameters:
Name Description
key field uid based on which the ordering should be done.
Example
blogQuery.descending('created_at')

skip(skip) → {Query}

This method skips the specified number of entries.
Parameters:
Name Description
skip number of entries to be skipped
Example
blogQuery.skip(5)

limit(limit) → {Query}

This method limits the response by providing only the specified number of entries.
Parameters:
Name Description
limit number of entries to be present in the result(at most)
Example
blogQuery.limit(10)

or(queries) → {Query}

This method performs the OR operation on the specified query objects and provides only the matching entries.
Parameters:
Name Description
queries array of Query objects/raw queries to be taken into consideration
Examples

.or with Query instances

let Query1 = Stack.ContentType('blog').Query().where('title', 'Demo')
let Query2 = Stack.ContentType('blog').Query().lessThan('comments', 10)
blogQuery.or(Query1, Query2)

.or with raw queries

let Query1 = Stack.ContentType('blog').Query().where('title', 'Demo').getQuery()
let Query2 = Stack.ContentType('blog').Query().lessThan('comments', 10).getQuery()
blogQuery.or(Query1, Query2)

and(queries) → {Query}

This method performs the AND operation on the specified query objects and provides only the matching entries.
Parameters:
Name Description
queries array of Query objects/raw queries to be taken into consideration
Examples

.and with Query instances

let Query1 = Stack.ContentType('blog').Query().where('title', 'Demo')
let Query2 = Stack.ContentType('blog').Query().lessThan('comments', 10)
blogQuery.and(Query1, Query2)

.and with raw queries

let Query1 = Stack.ContentType('blog').Query().where('title', 'Demo').getQuery()
let Query2 = Stack.ContentType('blog').Query().lessThan('comments', 10).getQuery()
blogQuery.and(Query1, Query2)

where(key, value) → {Query}

This method provides only the entries matching the specified value for a field.
Parameters:
Name Description
key uid of the field that is to be taken into consideration
value The value used to match or compare
Example
blogQuery.where('title','Demo')

count() → {Query}

This method provides only the number of entries matching the specified filters.
Example
blogQuery.count()

query(query) → {Query}

This method used to set raw queries on Query instance.
Parameters:
Name Description
query raw{json} queries to filter the entries in result set.

tags(values) → {Query}

The "tags" parameter allows you to specify an array of tags to search objects.
Parameters:
Name Description
values tags
Example
blogQuery.tags(['technology', 'business'])

includeCount() → {Query}

This method also includes the total number of entries returned in the response.
Example
blogQuery.includeCount()

AddParam() → {Query}

This method includes query parameter in query.
Example
blogQuery.addParam('include_count', 'true')

getQuery() → {Query}

returns the raw query which can be used for futher calls(.and/.or).

This method provides raw{json} queries based on the filters applied on Query objet.
Example
blogQuery.where('title','Demo').getQuery()

regex(key, value, optionsopt) → {Query}

This method provides only the entries matching the regular expression for the specified field.
Parameters:
Name Attributes Description
key Uid of the field that is to be taken into consideration
value The value used to match or compare
options <optional>
match or compare value in entry
Examples

.regex without options

blogQuery.regex('title','^Demo')

.regex with options

blogQuery.regex('title','^Demo', 'i')
This method is used to search data in entries.
Parameters:
Name Description
value value to search in entries
Example
blogQuery.search('Welcome to demo')

find()

Provides all the entries which satisfied the query specified.
Example
blogQuery.find()

findOne()

Provides the single entry from the resultset.
Deprecated:
  • since verion 3.3.0
Example
blogQuery.findOne()

toJSON() → {object}

Converts `Result` to plain javascript object.
Examples
blogEntry.then(function (result) {
     result = result.toJSON()
},function (error) {
     // error function
})
assetQuery.then(function (result) {
     result = result.toJSON()
},function (error) {
     // error function
})

get(field_uid) → {Object}

`get` to access the key value.
Parameters:
Name Description
field_uid
Examples
blogEntry.then(function (result) {
     let value = result.get(field_uid)
},function (error) {
     // error function
})
assetQuery.then(function (result) {
     let value = result.get(field_uid)
},function (error) {
     // error function
})

getDownloadUrl(string) → {Object}

`getDownloadUrl` to get the download url.
Parameters:
Name Description
string Disposition value
Example
assetQuery.then(function (result) {
     let value = result.getDownloadUrl(disposition_value)
},function (error) {
     // error function
})