Asset
Asset
Creates an instance of Assets. Use a UID to fetch a specific asset, or use the AssetLibrary class to retrieve all assets.
| Name | Type | Description |
|---|---|---|
| Uid (required) | string | Asset uid |
| Url | string | Asset URL |
| Description | string | Asset Description |
| FileName | string | File name for Asset |
| FileSize | string | File size of asset |
| Tags | object[] | Tags assign to asset |
SetHeader
| Name | Type | Description |
|---|---|---|
| key | string | header name. |
| value | string | header value against given header name. |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
Asset asset = await stack.Asset("asset_uid").SetHeader("custom_key", "custom_value").Fetch();RemoveHeader
| Name | Type | Description |
|---|---|---|
| key | string | key to be remove from header |
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
Asset asset = await stack.Asset("asset_uid").RemoveHeader("header_to_remove").Fetch();GetCreateAt
Get created at time.
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
Asset asset = await stack.Asset("asset_uid").Fetch();
DateTime date = asset.GetCreateAt();GetCreatedBy
Get created by user uid
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
Asset asset = await stack.Asset("asset_uid").Fetch();
string createBy = asset.GetCreatedBy();GetUpdateAt
Get updated at time.
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
Asset asset = await stack.Asset("asset_uid").Fetch();
DateTime date = asset.GetUpdateAt();GetUpdatedBy
Get Update by user uid
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
Asset asset = await stack.Asset("asset_uid").Fetch();
string createBy = asset.GetUpdatedBy();GetDeleteAt
Get deleted at time.
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
Asset asset = await stack.Asset("asset_uid").Fetch();
DateTime date = asset.GetDeleteAt();GetDeletedBy
Get Deleted by user uid
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
Asset asset = await stack.Asset("asset_uid").fetch();
string createBy = asset.GetDeletedBy();IncludeBranch
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
Asset asset = await stack.Asset("asset_uid").IncludeBranch().Fetch();IncludeFallback
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
Asset asset = await stack.Asset("asset_uid").IncludeFallback().Fetch();IncludeMetadata
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
Asset asset = await stack.Asset("asset_uid").IncludeMetadata().Fetch();Fetch
using Contentstack.Core;
using Contentstack.Core.Models;
ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
Asset asset = await stack.Asset("asset_uid").Fetch();AssetFields
The assetFields method specifies which asset-related fields are included in the API response when fetching an entry or querying entries.
Note The assetFields method is currently supported only in the North America (NA) region.
| Name | Type | Description |
|---|---|---|
| fields | string[] | Asset field names to include in the response. |
Returns the current instance to enable method chaining.
- Request behavior: No request is made until Fetch() (single asset) or FetchAll() (multiple assets) is called.
- Query parameter: When the request runs, the specified asset fields are sent to the CDA as the asset_fields[] query parameter.
Field Behavior
- Determines which asset-related metadata the CDA returns.
- Used with stack.Asset(uid).AssetFields(...).Fetch() or stack.AssetLibrary().AssetFields(...).FetchAll().
- When provided, the SDK sends the selected fields as the asset_fields[] query parameter. Only the requested asset metadata is returned.
Supported Values
- user_defined_fields
- embedded_metadata
- ai_generated_metadata
- visual_markups
Fetch a single asset with specific fields
using Contentstack.Core;
using Contentstack.Core.Configuration;
using Contentstack.Core.Models;
using Microsoft.Extensions.Options;
var options = new ContentstackOptions
{
ApiKey = "<API_KEY>",
DeliveryToken = "<DELIVERY_TOKEN>",
Environment = "<ENVIRONMENT>"
};
var stack = new ContentstackClient(new OptionsWrapper<ContentstackOptions>(options));
var assetResponse = await stack
.Asset("asset_uid")
.AssetFields(
"user_defined_fields",
"embedded_metadata",
"ai_generated_metadata",
"visual_markups"
)
.Fetch();Query multiple assets with asset fields
using Contentstack.Core;
using Contentstack.Core.Configuration;
using Contentstack.Core.Models;
using Microsoft.Extensions.Options;
var options = new ContentstackOptions
{
ApiKey = "<API_KEY>",
DeliveryToken = "<DELIVERY_TOKEN>",
Environment = "<ENVIRONMENT>"
};
var stack = new ContentstackClient(new OptionsWrapper<ContentstackOptions>(options));
var result = await stack
.AssetLibrary()
.AssetFields("ai_generated_metadata", "visual_markups")
.FetchAll();setLocale
The setLocale method sets the locale for fetching a single asset. The API returns the asset with localized metadata (for example, title and description), along with the locale and publish_details.locale fields in the response.
| Name | Type | Description |
|---|---|---|
| locale | string | Locale code used to fetch the asset. |
Field Behavior
- Specifies which locale’s metadata the API returns for the asset.
- Used with stack.Asset(uid).SetLocale(...).Fetch().
- When provided, the locale is sent as the locale query parameter.
Response Impact
The response includes localized fields (for example, title and description) along with locale and publish_details.locale.
Fetch a single asset in a locale
using Contentstack.Core;
using Contentstack.Core.Configuration;
using Contentstack.Core.Models;
using Microsoft.Extensions.Options;
var options = new ContentstackOptions
{
ApiKey = "<API_KEY>",
DeliveryToken = "<DELIVERY_TOKEN>",
Environment = "<ENVIRONMENT>"
};
var stack = new ContentstackClient(new OptionsWrapper<ContentstackOptions>(options));
var asset = await stack
.Asset("asset_uid")
.SetLocale("en-us")
.Fetch();
// Access localized fields from the response
var title = asset.Title; // Localized title
var locale = asset.Get("locale"); // e.g. "en-us"Fetch a single asset in a locale with a fallback
using Contentstack.Core;
using Contentstack.Core.Configuration;
using Contentstack.Core.Models;
using Microsoft.Extensions.Options;
var options = new ContentstackOptions
{
ApiKey = "<API_KEY>",
DeliveryToken = "<DELIVERY_TOKEN>",
Environment = "<ENVIRONMENT>"
};
var stack = new ContentstackClient(new OptionsWrapper<ContentstackOptions>(options));
var asset = await stack
.Asset("asset_uid")
.SetLocale("en-us")
.IncludeFallback()
.Fetch();Note
- IncludeFallback() returns content from the fallback locale if the requested locale is not published for the single asset.
- SetLocale can be chained with IncludeFallback(), IncludeMetadata(), AssetFields(), and AddParam() when fetching a single asset.