Asset Collection
Asset Collection
The Asset Collection provides methods for filtering and retrieving assets stored in Contentstack. You can retrieve specific assets by UID, tags, or metadata.
Example:
const result = stack.asset().find<BlogAsset>()
.then((assets) => console.log(assets))
.catch((error) => console.error("Error fetching assets:", error));addParams
The addParam method adds a query parameter to the query.
| Name | Type | Description |
|---|---|---|
| paramObj (required) | object | Add key-value pairs |
Example:
import { BaseAsset, FindAsset } from '@contentstack/delivery-sdk'
interface BlogAsset extends BaseAsset {
// other custom props
dimension: {
height: string;
width: string;
};
}
const asset = await stack
.asset()
.addParams({"key": "value"})
.find<BlogAsset>();find
The find method retrieves all the assets of the stack.
Example:
const result = await stack.asset().find<BlogAsset>();
includeBranch
The includeBranch method includes the branch details in the result.
Example:
const result = await stack.asset().includeBranch().find<BlogAsset>();
includeCount
The includeCount method retrieves count and data of all the objects in the result.
Example:
const asset = await stack.asset().includeCount().find<BlogAsset>();
includeDimension
The includeDimension method includes the dimensions (height and width) of the image in the result
Example:
const result = await stack.asset().includeDimension().find<BlogAsset>();
includeFallback
The includeFallback method retrieves the entry in its fallback language.
Example:
const result = await stack.asset().includeFallback().find<BlogAsset>();
locale
The locale method retrieves the asset published in the specified locale.
| Name | Type | Description |
|---|---|---|
| locale (required) | string | Locale of the asset |
Example:
const result = await stack.asset().locale('en-us').find<BlogAsset>();orderByAscending
The orderByAscending method sorts the results in ascending order based on the specified field UID.
| Name | Type | Description |
|---|---|---|
| key (required) | string | Field UID to sort the results |
Example:
const asset = await stack.asset().orderByAscending().find<BlogAsset>();
orderByDescending
The orderByDescending method sorts the results in descending order based on the specified key.
| Name | Type | Description |
|---|---|---|
| key (required) | string | Field UID to sort the results |
Example:
const asset = await stack.asset().orderByDescending().find<BlogAsset>();
param
The param method adds query parameters to the URL.
| Name | Type | Description |
|---|---|---|
| key (required) | string | Add any param to include in the response |
| value (required) | string/number | Add the corresponding value of the param key |
Example:
const asset = await stack.asset().param("key", "value").find<BlogAsset>();relativeUrls
The relativeUrls method includes the relative URLs of all the assets in the result.
Example:
const result = await stack.asset().relativeUrls().find<BlogAsset>();
removeParam
The removeParam method removes a query parameter from the query.
| Name | Type | Description |
|---|---|---|
| key (required) | string | Specify the param key you want to remove |
Example:
const asset = await stack.asset().removeParam("query_param_key").find<BlogAsset>();version
The version method retrieves a specific version of the asset in the result.
| Name | Type | Description |
|---|---|---|
| version (required) | number | Version number of the asset |
Example:
const result = await stack.asset().version(1).find<BlogAsset>();
where
The where method filters the results based on the specified criteria.
| Name | Type | Description |
|---|---|---|
| fieldUid (required) | string | Specify the field the comparison is made from |
| queryOperation (required) | QueryOperationEnum | Specify the comparison criteria |
| fields (required) | string | Specify the field the comparison is made to |
Example:
const result = await stack.asset().query().
where("field_UID", QueryOperation.IS_LESS_THAN, ["field1", "field2"])
.find<BlogAsset>();includeMetadata
The includeMetadata method includes the metadata for getting metadata content for the entry.
Example:
const result = await stack.asset().includeMetadata().find<BlogAsset>();
skip
The skip method will skip a specific number of assets in the output.
| Name | Type | Description |
|---|---|---|
| skipBy (required) | int | Enter the number of assets to be skipped. |
Example:
const result = await stack.asset().skip(5).find<BlogAsset>();
limit
The limit method will return a specific number of assets in the output.
| Name | Type | Description |
|---|---|---|
| limit (required) | int | Enter the maximum number of assets to be returned. |
Example:
const result = await stack.asset().limit(5).find<BlogAsset>();