Filters over the MetaData in assets - Squidex.ClientLibrary

I wanted to set a filter for the query of assets.

var data = await _apiClientManager.CreateAssetsClient().GetAssetsAsync(
                    _settings.AppName,
                    new AssetQuery
                    {
                        Filter = filter,
                        OrderBy = orderBy
                    },
                    CancellationToken.None);

I need different assets with a certain content in the metadata.

I tried the following without success:

$“metadata/key eq ‘value’”
$“metadata/key/iv eq ‘value’”
$“any(metadata/value eq ‘value’)”

is there a trick to filter assets by metadata?

Greetings Andreas

No, this should work.

I have added a test to the API tests:

// STEP 1: Create asset
var asset_1 = await _.UploadFileAsync("Assets/logo-squared.png", "image/png");


// STEP 2: Query asset by pixel width.
var assets_1 = await _.Assets.GetAssetsAsync(_.AppName, new AssetQuery
{
	Filter = "metadata/pixelWidth eq 600"
});

Assert.Contains(assets_1.Items, x => x.Id == asset_1.Id);


// STEP 3: Add custom metadata.
asset_1.Metadata["custom"] = "foo";

await _.Assets.PutAssetAsync(_.AppName, asset_1.Id.ToString(), new AnnotateAssetDto
{
	Metadata = asset_1.Metadata
});


// STEP 4: Query asset by custom metadata
var assets_2 = await _.Assets.GetAssetsAsync(_.AppName, new AssetQuery
{
	Filter = "metadata/custom eq 'foo'"
});

Assert.Contains(assets_2.Items, x => x.Id == asset_1.Id);

ok, if you know that it’s great!

Thank you :slight_smile: