Using Metadata
I'm trying to use the C# API to find folders within a metadata template and with a certain metadata value. I've found a couple examples, but nothing restricting on metadata values. I'm trying this:
List metadataFilters = new List();
BoxMetadataFilterRequest mfr = new BoxMetadataFilterRequest();
mfr.TemplateKey = "Retail Lending Document";
mfr.Scope = "enterprise";
mfr.Filters = $"Case ID: {searchKeyword}";
metadataFilters.Add(mfr);
BoxCollection childResults = box.UserClient.SearchManager.SearchAsync(
ancestorFolderIds: new string[] { folderId },
type: "folder",
limit: 999,
mdFilters: metadataFilters
).Result;
which returns bad_request. The parent folder exists and contains a folder with that metadata template. The metadata field name does have a space in it, so cannot be assigned within a filter object such as new { Case Id=searchKeyword }.
How can I search matching on metadata value using the C# API?
Thanks!
-
Hi ,
A 400 indicates a bad request which in this case, indicates an issue with the input provided to the SearchAsycnc method. At first glance of your code, it looks like the Filters object might not be in the correct format. Take a look at this example snippet which sets up the same kind of filter and see if it helps get you going.
It also looks like the templateKey value is invalid. The template key should be camel case and also be a valid Metadata template that exists in your enterprise. You can get more info on Metadata (including how to get available templateKeys) with the API from the Box Developer Site here.
Please sign in to leave a comment.
Comments
1 comment