List all metadata on an item

List all metadata on an item

Metadata instances can be listed for either a file or a folder.

List metadata on a file

To list all metadata instances on a file, call the GET /files/:file_id/metadata API endpoint.

cURL
curl -i -X GET "https://api.box.com/2.0/files/12345/metadata" \
     -H "Authorization: Bearer <ACCESS_TOKEN>"
Java
BoxFile file = new BoxFile(api, "id");
Iterable<Metadata> metadataList = file.getAllMetadata();
for (Metadata metadata : metadataList) {
    // Do something with the metadata.
}
Python
file_metadata = client.file(file_id='11111').get_all_metadata()
for instance in file_metadata:
    if 'foo' in instance:
        print('Metadata instance {0} has value "{1}" for foo'.format(instance['id'], instance['foo']))
iOS
client.metadata.list(forFileId: "11111") { (result: Result<[MetadataObject], BoxSDKError>) in
    guard case let .success(metadata) = result {
        print("Error retrieving metadata")
        return
    }

    print("Retrieved \(metadata.count) metadata instances:")
    for instance in metadata {
        print("- \(instance.template)")
    }
}

This API does not support paging and it will always return all of the metadata instances for this file.

List metadata on a folder

To list all metadata instances on any folder (except for the root folder), call the GET /folders/:file_id/metadata API endpoint.

cURL
curl -i -X GET "https://api.box.com/2.0/folders/4353455/metadata" \
     -H "Authorization: Bearer <ACCESS_TOKEN>"
Java
BoxFolder file = new BoxFolder(api, "id");
Iterable<Metadata> metadataList = folder.getAllMetadata();
for (Metadata metadata : metadataList) {
    // Do something with the metadata.
}
Python
folder_metadata = client.folder(folder_id='22222').get_all_metadata()
for instance in folder_metadata:
    if 'foo' in instance:
        print('Metadata instance {0} has value "{1}" for foo'.format(instance['id'], instance['foo']))
iOS
client.metadata.list(forFolderId: "22222") { (result: Result<[MetadataObject], BoxSDKError>) in
    guard case let .success(metadata) = result {
        print("Error retrieving metadata")
        return
    }

    print("Retrieved \(metadata.count) metadata instances:")
    for instance in metadata {
        print("- \(instance.template)")
    }
}

This API does not support paging and it will always return all of the metadata instances for this file. This API can not be used on the root folder with ID 0.