Namespace: microsoft.graph
Retrieve the contents of a specific version of a driveItem.
Note: Getting the content of the current version is not supported. To do that, use the Download the contents of a driveItem method.
This API is available in the following national cloud deployments.
Global service |
US Government L4 |
US Government L5 (DOD) |
China operated by 21Vianet |
✅ |
✅ |
✅ |
✅ |
Permissions
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it. For details about delegated and application permissions, see Permission types. To learn more about these permissions, see the permissions reference.
Permission type |
Least privileged permissions |
Higher privileged permissions |
Delegated (work or school account) |
Files.Read |
Files.Read.All, Files.ReadWrite, Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All |
Delegated (personal Microsoft account) |
Files.Read |
Files.Read.All, Files.ReadWrite, Files.ReadWrite.All |
Application |
Files.Read.All |
Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All |
HTTP request
GET /drives/{drive-id}/items/{item-id}/versions/{version-id}/content
GET /groups/{group-id}/drive/items/{item-id}/versions/{version-id}/content
GET /me/drive/items/{item-id}/versions/{version-id}/content
GET /sites/{site-id}/drive/items/{item-id}/versions/{version-id}/content
GET /users/{user-id}/drive/items/{item-id}/versions/{version-id}/content
Response
Returns a 302 Found
response redirecting to a preauthenticated download URL for the bytes of the file.
To download the contents of the file your application needs to follow the Location
header in the response.
Many HTTP client libraries will automatically follow the 302 redirection and start downloading the file immediately.
Preauthenticated download URLs are only valid for a short period of time (a few minutes) and don't require an Authorization
header to download.
Example
This example retrieves a version of a file in the current user's drive.
Request
GET /me/drive/items/{item-id}/versions/{version-id}/content
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Versions["{driveItemVersion-id}"].Content.GetAsync();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
mgc drives items versions content get --drive-id {drive-id} --drive-item-id {driveItem-id} --drive-item-version-id {driveItemVersion-id}
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
//other-imports
)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").Versions().ByDriveItemVersionId("driveItemVersion-id").Content().Get(context.Background(), nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").versions().byDriveItemVersionId("{driveItemVersion-id}").content().get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
const options = {
authProvider,
};
const client = Client.init(options);
let stream = await client.api('/me/drive/items/{item-id}/versions/{version-id}/content')
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
<?php
use Microsoft\Graph\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->versions()->byDriveItemVersionId('driveItemVersion-id')->content()->get()->wait();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
Import-Module Microsoft.Graph.Files
Get-MgDriveItemVersionContent -DriveId $driveId -DriveItemId $driveItemId -DriveItemVersionId $driveItemVersionId
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').versions.by_drive_item_version_id('driveItemVersion-id').content.get()
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
Response
The call returns a redirect to where the contents of the version can be downloaded.
HTTP/1.1 302 Found
Location: https://onedrive.com/34FF49D6...
OneDrive doesn't preserve the complete metadata for previous versions of a file.
When your app retrieves the list of available versions for a file, a driveItemVersion resource is returned that provides the available information about the specific version.