Assets

View as Markdown

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

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

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

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()