I would like to retrieve the latest file version identifier for each file when listing the contents of a folder, or when asking for metadata for a single drive item.
The DriveItem
resource does not contain any version
information, versions are retrievable for single items only with an additional API call.
Doing an additional API call for each file when I'm listing a folder that has several files in it is something I want to avoid.
Is there an efficient way to retrieve the latest version id for a listing (or single file), without having to do additional API requests, and especially without having to do n + 1 requests in the case of folder contents listing?
You can use $expand=versions
query option to query for all the versions alongside the DriveItem information. This will list out all the versions on that item and you can select the first one to get the latest one.
A sample graph explorer query would look like following:
https://graph.microsoft.com/v1.0/me/drives/{drive-id}/items/{item-id}?$expand=versions