AssetLibrary

View as Markdown

AssetLibrary

Get all asset from Stack

SetHeader

To set headers for Contentstack rest calls.

NameTypeDescription
keystring

header name.

valuestring

header value against given header name.

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Asset> asset = await stack.AssetLibrary().SetHeader("custom_key", "custom_value").FindAll();

RemoveHeader

Remove header key.

NameTypeDescription
keystring

key to be remove from header

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Asset> asset = await stack.AssetLibrary("asset_uid").RemoveHeader("header_to_remove").FindAll();

SortWithKeyAndOrderBy

Sorts the assets in the given order on the basis of the specified field.
NameTypeDescription
keystring

Field UID

orderstring

ordering for sorting from key

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Asset> asset = await stack.AssetLibrary().SortWithKeyAndOrderBy("field_uid", "order").FindAll();

SetLocale

Sets the locale.



NameTypeDescription
localestring

Locale to be fetch

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Asset> assets = await stack.AssetLibrary().SetLocale("en-us").FetchAll();

Skip

The number of objects to skip before returning any.

NameTypeDescription
numberint

No of objects to skip from returned objects.

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Asset> assets = await stack.AssetLibrary().Skip(20).FetchAll();

Limit

A limit on the number of objects to return.

NameTypeDescription
numberint

No of objects to limit.

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Asset> assets = await stack.AssetLibrary().Limit(20).FetchAll();

IncludeBranch

Include branch for publish content.

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Asset> assets = await stack.AssetLibrary().IncludeBranch().FindAll();

IncludeCount

This method also includes the total number of assets returned in the response.



using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Asset> assets = await stack.AssetLibrary().IncludeCount().FindAll();

IncludeFallback

Include fallback locale publish content, if specified locale content is not publish.

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Asset> assets = await stack.AssetLibrary().IncludeFallback().FindAll();

IncludeMetadata

The includeMetadata method will add the meta information to the response.

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Asset> assets = await stack.AssetLibrary().IncludeMetadata().FindAll();

Except

Specifies list of field uids that would be excluded from the response.

NameTypeDescription
fieldUidsSystem.String[]

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

AssetLibrary assetLibrary = await stack.AssetLibrary().Except(new String[]{"name", "description"}).FetchAll();

Only

Specifies an array of 'only' keys in BASE object that would be 'included' in the response.

NameTypeDescription
fieldUidSystem.String[]

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

AssetLibrary assetLibrary = await stack.AssetLibrary().Only(new String[]{"name", "description"}).FetchAll();

IncludeRelativeUrls

This method includes the relative url of assets.



using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Asset> assets = await stack.AssetLibrary().IncludeRelativeUrls().FindAll();

FetchAll

Execute a AssetLibrary and Caches its result (Optional)

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

ContentstackCollection<Asset> assets = await stack.AssetLibrary().FetchAll();

Count

Total count of the asset in specified Stack

using Contentstack.Core; 

using Contentstack.Core.Models;


ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");

AssetLibrary assetLibrary = await stack.AssetLibrary().Count();

Query

AssetLibrary Query allows you to retrieve assets that match specific query criteria, returning a comprehensive list of assets that meet the defined parameters.

NameTypeDescription
queryObjectJsonObject

The query contains the parameters needed to fetch assets and supports nested structures when required.

Example:

using Contentstack.Core; 

using Contentstack.Core.Models;

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");


JsonObject queryObject = new JsonObject

{

  { "filename", "image3.png" }

};


ContentstackCollection<Asset> assets = await stack.AssetLibrary().Query(queryObject).FetchAll();
NoteYou can also include nested queries as needed, similar to those used in Content Delivery API Queries
JsonObject queryObject = new JsonObject
{
{ "bank_offers.card_type", new JsonObject { ["$ne"] = "Debit Card" } }
};

Tags

The tags method retrieves all assets associated with the specified tag

NameTypeDescription
tagsstring[]

An array of tag strings used to filter assets; returns assets matching any specified tag. If null or empty, no tag filtering is applied.

Example:

ContentstackClient stack = new ContentstackClient("api_key", "delivery_token", "environment");
AssetLibrary assetLibrary = stack.AssetLibrary();
assetLibrary.Tags(new string[] {"banner"});
ContentstackCollection<Asset> assets = await assetLibrary.FetchAll();