Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 19 Next »

Welcome to the Digizuite C# SDK documentation. Here you will find documentation on how to use the sdk and some tips and tricks for interacting with the Digizuite in general.

Setup

To get started with the Digizuite SDK, you should first install the Digizuite packages from nuget.org https://www.nuget.org/packages/Digizuite.Sdk.
Additionally the SDK has to be initialized. If you are using dotnet, an extension method AddDigizuite is provided. Use the extension method AddDigizuite for inspiration.

A simple example of how the initialization code looks in a console application is as follows:

var serviceCollection = new ServiceCollection(); 

var config = new DigizuiteConfiguration()
{
	BaseUrl = new Uri("https://<Digizuite url>.com/"),
	SystemUsername = "<Username>",
	SystemPassword = "<Password>"
};

serviceCollection.AddDigizuite(config)
            .AddDigizuiteLogging()
            .AddConsoleSink();
serviceCollection.AddSingleton(typeof(ILogger<>), typeof(ConsoleLogger<>));
var serviceProvider = serviceCollection.BuildServiceProvider(true);

Usecases - Asset Search

  1. Get a single asset by assetId
    Use the Digizuite service IAssetSearchService

    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

  2. Get a list of assets
    Use the Digizuite service IAssetSearchService

    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

  3. Freetext search for assets and sort by assetId desending
    Use the Digizuite service IAssetSearchService
    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.

    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); 

  4. Search by assettype
    Use the Digizuite service IAssetSearchService
    Search for a specific assettype InDesign.

    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);

  5. Search by metafield Folders
    Use the Digizuite service IAssetSearchService
    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.

    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);

  6. Search by date range
    Use the Digizuite service IAssetSearchService
    Search assets that has been uploaded in a specific date range.

    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);
    }

Usecases - Asset metadata update

In the following we show how you can update the different metafield types on an asset.

  1. BIT
    Use the Digizuite service IAssetSearchService and IMetadataValueService.
    First we fetch the asset. Then creates a new instance of BitMetadataUpdate. The TargetItemIds is the itemId of the asset we just fetched. The MetaFieldItemGuid is the GUID of the metafield you wants to update. As you can see in the ApplyUpdate, it takes a list of updates. So you have the options to bulk update metadata for an asset.

    var assetSearchService = app.Services.GetRequiredService<IAssetSearchService>();
    var metadataValueService = app.Services.GetRequiredService<IMetadataValueService>();
    var asset = await assetSearchService.GetAsset(75);
    var metadataUpdate = new BitMetadataUpdate
    {
        Value = true,
        TargetItemIds = new HashSet<int> { asset.ItemId },
        MetaFieldItemGuid = Guid.Parse("<GUID of Metafield>")
    };
    await metadataValueService.ApplyUpdate<MetadataUpdate>(new[] { metadataUpdate});

  2. INT
    Use the Digizuite service IAssetSearchService and IMetadataValueService.
    First we fetch the asset. Then creates a new instance of IntMetadataUpdate. The TargetItemIds is the itemId of the asset we just fetched. The MetaFieldItemGuid is the GUID of the metafield you wants to update. As you can see in the ApplyUpdate, it takes a list of updates. So you have the options to bulk update metadata for an asset.

    var assetSearchService = app.Services.GetRequiredService<IAssetSearchService>();
    var metadataValueService = app.Services.GetRequiredService<IMetadataValueService>();
    var asset = await assetSearchService.GetAsset(75);
    var metadataUpdate = new IntMetadataUpdate
    {
        Value = 99,
        TargetItemIds = new HashSet<int> { asset.ItemId },
        MetaFieldItemGuid = Guid.Parse("<GUID of Metafield>")
    };
    await metadataValueService.ApplyUpdate<MetadataUpdate>(new[] { metadataUpdate});

  3. STRING
    Use the Digizuite service IAssetSearchService and IMetadataValueService.
    First we fetch the asset. Then creates a new instance of StringMetadataUpdate. The TargetItemIds is the itemId of the asset we just fetched. The MetaFieldItemGuid is the GUID of the metafield you wants to update. As you can see in the ApplyUpdate, it takes a list of updates. So you have the options to bulk update metadata for an asset.

    var assetSearchService = app.Services.GetRequiredService<IAssetSearchService>();
    var metadataValueService = app.Services.GetRequiredService<IMetadataValueService>();
    var asset = await assetSearchService.GetAsset(75);
    var metadataUpdate = new StringMetadataUpdate
    {
        Value = "Update metafield string",
        TargetItemIds = new HashSet<int> { asset.ItemId },
        MetaFieldItemGuid = Guid.Parse("<GUID of Metafield>")
    };
    await metadataValueService.ApplyUpdate<MetadataUpdate>(new[] { metadataUpdate});

  4. COMBOVALUE
    Use the Digizuite service IAssetSearchService and IMetadataValueService.
    First we fetch the asset. Then creates a new instance of ComboValueMetadataUpdate. The TargetItemIds is the itemId of the asset we just fetched. The MetaFieldItemGuid is the GUID of the metafield you wants to update.
    The ComboValue can either be set to an existing combovalue or create an new combovalue.
    new ExistingCombo(50170) or new DynamicCombo { Label = "test" , OptionValue = "test" }.
    As you can see in the ApplyUpdate, it takes a list of updates. So you have the options to bulk update metadata for an asset.

    var assetSearchService = app.Services.GetRequiredService<IAssetSearchService>();
    var metadataValueService = app.Services.GetRequiredService<IMetadataValueService>();
    var asset = await assetSearchService.GetAsset(75);
    var metadataUpdate = new ComboValueMetadataUpdate
    {
        ComboValue = new ExistingCombo(50170),
        TargetItemIds = new HashSet<int> { asset.ItemId },
        MetaFieldItemGuid = Guid.Parse("<GUID of Metafield>")
    };
    await metadataValueService.ApplyUpdate<MetadataUpdate>(new[] { metadataUpdate});

  5. MULTICOMBOVALUE

  6. DATETIME

  7. TREE

  8. EDITCOMBOVALUE

  9. EDITMULTICOMBOVALUE

  • No labels