...
Get a single asset by assetId
Use the Digizuite serviceIAssetSearchService
Code Block var assetSearchService = serviceProvider.GetRequiredService<IAssetSearchService>(); var assetResponse = await assetSearchService.GetAsset(75);
The response model can be found at DC 5.8 [core api] Get assets
Get a list of assets
Use the Digizuite serviceIAssetSearchService
Code Block var assetSearchService = serviceProvider.GetRequiredService<IAssetSearchService>(); var getAssetsRequest = new GetAssetsRequest { AssetIds = new HashSet<int> { 75, 76 } }; var assetResponse = await assetSearchService.GetAssets(getAssetsRequest);
The response model can be found at DC 5.8 [core api] Get assets
Freetext search for assets and sort by assetId desending
Use the Digizuite serviceIAssetSearchService
Here we search for assets with the following search criteria:
Freetext.
Count, the number of assets pr page.
Skip, set to 0, which is page 1.
SortBy, here we sort by the highest assetId.Code Block var assetSearchService = serviceProvider.GetRequiredService<IAssetSearchService>(); var assetSearchRequestFreetext = new AssetSearchRequest() { FreeText = "Test", Count = 12, Skip = 0, SortBy = new List<SortField> { new SortField { Order = SortOrder.Descending, SearchKey = "assetId" } } }; var assetResponse = await assetSearchService.SearchForAssets(assetSearchRequestFreetext);
Search by assettype
Use the Digizuite serviceIAssetSearchService
Search for a specific assettypeInDesign.
Code Block var assetSearchService = serviceProvider.GetRequiredService<IAssetSearchService>(); var assetSearchRequestAssettype = new AssetSearchRequest() { FacetFields = new List<FacetRequest> { new FacetRequest { SearchKey = "assetType", Operation = LogicalComparison.Or, Recursive = false, Values = new List<string>{ "InDesign" } } }, Count = 12, Skip = 0 }; var assetResponse = await assetSearchService.SearchForAssets(assetSearchRequestAssettype);
Search by metafield Folders
Use the Digizuite serviceIAssetSearchService
The searchKey is the guid of the metafield Folders. The Folder metafield is of type tree.
The values, are the tree nodes id’s of the metafield Folder.Code Block var assetSearchService = serviceProvider.GetRequiredService<IAssetSearchService>(); var assetSearchRequestFolders = new AssetSearchRequest() { FacetFields = new List<FacetRequest> { new FacetRequest { Operation = LogicalComparison.And, SearchKey = "bf0ad1a6-984a-494e-a227-9d70c6a864f9", Recursive = false, Values = new List<string>{ "2" } } }, Count = 12, Skip = 0 }; var assetResponse = await assetSearchService.SearchForAssets(assetSearchRequestFolders);
Search by date range
Use the Digizuite serviceIAssetSearchService
Search assets that has been uploaded in a specific date range.Code Block var assetSearchService = serviceProvider.GetRequiredService<IAssetSearchService>(); if (Period.TryParse("2023-06-05T00:00:00.000", "2023-07-04T14:42:54.860", out var dateRangePeriod)) { var assetSearchRequestDateRange = new AssetSearchRequest() { FacetFields = new List<FacetRequest> { new FacetRequest { DateRange = dateRangePeriod, Operation = LogicalComparison.Or, SearchKey = "uploadDate", Recursive = false } }, Count = 12, Skip = 0 }; var assetResponse = await assetSearchService.SearchForAssets(assetSearchRequestDateRange); }
Get all assets in a channel
If you need to get all assets in a channel and the channel contains more then 10.000 assets, then it has to be requested in a special way. Our search engine elastic has a limitation of 10.000.Code Block language c# var result = new List<AssetResponse>(); var nextAssetId = -1; var assetIdFacetRequest = new FacetRequest() { FacetMode = FacetMode.QueryOnly, LongRange = new LongRange() { From = nextAssetId, }, SearchKey = "assetId" }; var facets = new List<FacetRequest>() { new FacetRequest() { FacetMode = FacetMode.QueryOnly, Recursive = true, SearchKey = "channelFolder", Values = new List<string> { "126" } }, assetIdFacetRequest, }; var batchSize = 12; var searchRequest = new AssetSearchRequest() { SortBy = new List<SortField> { new SortField() { SearchKey = "assetId", Order = SortOrder.Ascending } }, FacetFields = facets, Count = batchSize }; while (true) { assetIdFacetRequest.LongRange.From = nextAssetId; var rest = await _assetSearchService.SearchForAssets(searchRequest); if (rest.Items.Count <= 1) { break; } result.AddRange(rest.Items); nextAssetId = rest.Items.Max(r => r.AssetId); } Console.WriteLine($"Get All assets in channel, found {result.Count}.");