Asset
Asset
Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use. These files can be attached and used in multiple entries.
update
The Update Asset call lets you update the name and description of an existing Asset.
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset('uid')
.fetch()
.then((asset) => {
asset.title = 'My New asset'
asset.description = 'Asset description'
return asset.update()
})
.then((asset) => console.log(asset))delete
The Delete asset call will delete an existing asset from the stack.
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset('uid')
.delete()
.then((response) => console.log(response.notice))fetch
| Name | Type | Description |
|---|---|---|
| params.version | number | Enter the version number of the asset that you want to retrieve. However, to retrieve a specific version of an entry, you need to keep the environment parameter blank. |
| params.include_publish_details | string | Enter 'true' to include the publish details of the entry. |
| include_asset_scan_status | Boolean | When true, includes the _asset_scan_status field in the asset response (pending, clean, quarantined, or not_scanned). Opt-in; omitted from the request by default. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset('uid')
.fetch()
.then((asset) => console.log(asset))replace
The Replace asset call will replace an existing asset with another file on the stack.
| Name | Type | Description |
|---|---|---|
| params.asset (required) | object | Asset details to replace. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const asset = {
upload: 'path/to/file.png',
title: 'Title',
description: 'Desc'
}
client.stack({ api_key: 'api_key'}).asset('uid').replace(asset)
.then((asset) => console.log(asset))publish
The publish call is used to publish a specific version of an asset on the desired environment either immediately or at a later date/time.
| Name | Type | Description |
|---|---|---|
| params.publishDetails (required) | object | Details of asset to be publish. |
| params.locale | string | Enter the code of the locale that the entry belongs to. |
| params.version | number | Asset version to be publish |
| params.scheduledAt | string | Schedule date for publishing Asset. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const asset = {
"locales": [
"en-us"
],
"environments": [
"development"
]
}
client.stack({ api_key: 'api_key'}).asset('uid')
.publish({ publishDetails: asset, locale: "en-us", version: 1, scheduledAt: "2019-02-08T18:30:00.000Z"})
.then((response) => console.log(response.notice))unpublish
The unpublish call is used to unpublish a specific version of an asset on the desired environment either immediately or at a later date/time.
| Name | Type | Description |
|---|---|---|
| params.publishDetails (required) | object | Details of asset to be unpublished. |
| params.locale | string | Enter the code of the locale that the entry belongs to. |
| params.version | number | Asset version to be publish |
| params.scheduledAt | string | Schedule date for publishing Asset. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const asset = {
"locales": [
"en-us"
],
"environments": [
"development"
]
}
client.stack({ api_key: 'api_key'}).asset('uid')
.unpublish({ publishDetails: asset, locale: "en-us", version: 1, scheduledAt: "2019-02-08T18:30:00.000Z"})
.then((response) => console.log(response.notice))folder
The Folder allows to fetch and create folders in assets.
| Name | Type | Description |
|---|---|---|
| uid | string | Folder uid to perform operation |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset().folder()
OR
client.stack({ api_key: 'api_key'}).asset().folder('folder_uid')create
The Create an asset call creates a new asset.
| Name | Type | Description |
|---|---|---|
| params.asset (required) | object | Asset details to create. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
const asset = {
upload: 'path/to/file.png',
title: 'Title',
description: 'Desc'
}
client.stack({ api_key: 'api_key'}).asset().create(asset)
.then((asset) => console.log(asset))query
| Name | Type | Description |
|---|---|---|
| params.include_publish_details | boolean | Enter 'true' to include the publish details of the entry. |
| params.query | object | Queries that you can use to fetch filtered results. |
| include_asset_scan_status | Boolean | When true, includes the _asset_scan_status field in the asset response (pending, clean, quarantined, or not_scanned). Opt-in; omitted from the request by default. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset()
.query({ query: { filename: 'Asset Name' } })
.find()
.then((asset) => console.log(asset))download
The Download function will get downloadable file in specified format.
| Name | Type | Description |
|---|---|---|
| param.url | string | The url for the asset to download |
| param.responseType | string | Optional parameter to specify the response type. |
import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset('uid')
.fetch()
.then((asset) => asset.download({responseType: 'blob'}))
.then((response) => // Write response data to destination file. )import * as contentstack from '@contentstack/management'
const client = contentstack.client({ authtoken })
client.stack({ api_key: 'api_key'}).asset()
.download({url: 'asset_url_to_download', responseType: 'blob'})
.then((response) => // Write response data to destination file. )