Get metadata from Search API

I am trying to call the Box api with c# and search for documents and get their metadata. I am able to see the metadata when I pass “metadata.enterprise.{metadata_template_key}” in a string array into the fields for the Search Manager. How am I able to extract that data? I do not see a way to get it from the BoxItem type. I know I can make a second call to get the metadata directly but I would have to make this call on all the documents the search api returned. I would like to prevent making so many calls if possible.

Hi @cdeleon , welcome to the forum.

To get the actual metadata values for a file (it’s similar for folders) you will need the file_id, the template_scope, and the template_key.

To get these id’s I use the GET https://{{}}/2.0/metadata_templates/enterprise end point.

Then it’s a matter of querying the file metadata.

For example:

curl --location '' \
--header 'Authorization: Bearer 8k...y8'

Results in:

    "$id": "45bd22c2-c964-4ddb-89aa-0d6f31ea2236",
    "$version": 0,
    "$type": "demoMediaMetadata-d2c5ef83-23c1-4bb5-8486-7833cfa7c9f4",
    "$parent": "file_1121082178302",
    "$typeVersion": 0,
    "$template": "demoMediaMetadata",
    "$scope": "enterprise_877840855",
    "fileName": "BigBuckBunny.mp4",
    "streamIdentifier": "0",
    "trackType": "General",
    "otherFrameRate": "24.000 FPS",
    "videoFormatWithhintList": "AVC",
    "formatExtensionsUsuallyUsed": "mov mp4 m4v m4a m4b m4p m4r 3ga 3gpa 3gpp 3gp 3gpp2 3g2 k3g jpm jpx mqv ismv isma ismt f4a f4b f4v",
    "headersize": "179655",
    "proportionOfThisStream": "0.00114",
    "count": "336",
    "otherStreamSize": "175 KiB (0%), 175 KiB, 175 KiB, 175 KiB, 175.5 KiB, 175 KiB (0%)",
    "otherDuration": "9 min 56 s, 9 min 56 s 473 ms, 9 min 56 s, 00:09:56.473, 00:09:56:11, 00:09:56.473 (00:09:56:11)",
    "otherKindOfStream": "General",
    "audioCodecs": "AAC LC",
    "isstreamable": "Yes",
    "gssd": "BADC219C2HH1385162467077729",
    "datasize": "157828719",
    "otherFileName": "download",
    "otherFormat": "MPEG-4",
    "format": "MPEG-4",
    "kindOfStream": "General",
    "otherOverallBitRate": "2 119 kb/s",
    "videoFormatList": "AVC",
    "otherCodecId": "mp42 (isom/avc1/mp42)",
    "folderName": "/All Files/Media Samples/Video",
    "taggedDate": "UTC 2010-01-10 08:29:06",
    "countOfStreamOfThisKind": "1",
    "completeName": "/All Files/Media Samples/Video/BigBuckBunny.mp4",
    "fileExtension": ".mp4",
    "gshh": "",
    "gstd": "596961",
    "frameRate": "24.000",
    "gsst": "0",
    "fileSize": 158008374,
    "duration": 596473,
    "otherFileSize": "151 MiB, 151 MiB, 151 MiB, 151 MiB, 150.7 MiB",
    "audioFormatList": "AAC LC",
    "footersize": "0",
    "codecidCompatible": "isom/avc1/mp42",
    "audioFormatWithhintList": "AAC LC",
    "overallBitRate": 2119236,
    "countOfVideoStreams": "1",
    "frameCount": "14315",
    "overallBitRateMode": "VBR",
    "otherOverallBitRateMode": "Variable",
    "codecIdUrl": "",
    "formatProfile": "Base Media / Version 2",
    "countOfAudioStreams": "1",
    "codecsVideo": "AVC",
    "commercialName": "MPEG-4",
    "internetMediaType": "video/mp4",
    "streamSize": 179663,
    "encodedDate": "UTC 2010-01-10 08:29:06",
    "codecId": "mp42",
    "$canEdit": true

By the way this examples comes from this article, if you’re interested in the context:

I’m not versed on the C# SDK, but see if this example from the SDK helps you: