Get Drive
Article
01/20/2022
8 minutes to read
10 contributors
In this article
Namespace: microsoft.graph
Retrieve the properties and relationships of a Drive resource.
A Drive is the top-level container for a file system, such as OneDrive or SharePoint document libraries.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
Files.Read, Files.ReadWrite, Files.Read.All, Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All
Delegated (personal Microsoft account)
Files.Read, Files.ReadWrite, Files.Read.All, Files.ReadWrite.All
Application
Files.Read.All, Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All
Get current user's OneDrive
The signed in user's drive (when using delegated authentication) can be accessed from the me
singleton.
If a user's OneDrive is not provisioned but the user has a license to use OneDrive, this request will automatically provision the user's drive, when using delegated authentication.
HTTP request
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var drive = await graphClient.Me.Drive
.Request()
.GetAsync();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/drive"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
MSGraphDrive *drive = [[MSGraphDrive alloc] initWithData:data error:&nserror];
}];
[meDataTask execute];
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Drive drive = graphClient.me().drive()
.buildRequest()
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
result, err := graphClient.Me().Drive().Get()
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Get a user's OneDrive
To access a user's OneDrive or OneDrive for Business, your app must request the drive relationship on the User resource.
If a user's OneDrive is not provisioned but the user has a license to use OneDrive, this request will automatically provision the user's drive, when using delegated authentication.
HTTP request
GET /users/{idOrUserPrincipalName}/drive
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var drive = await graphClient.Users["{user-id}"].Drive
.Request()
.GetAsync();
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 drive = await client.api('/users/{idOrUserPrincipalName}/drive')
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/users/{idOrUserPrincipalName}/drive"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
MSGraphDrive *drive = [[MSGraphDrive alloc] initWithData:data error:&nserror];
}];
[meDataTask execute];
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Drive drive = graphClient.users("{idOrUserPrincipalName}").drive()
.buildRequest()
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
userId := "user-id"
result, err := graphClient.UsersById(&userId).Drive().Get()
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Path parameters
Parameter name
Value
Description
idOrUserPrincipalName
string
Required. The identifier for the user object who owns the OneDrive.
Get the document library associated with a group
To access a Group's default document library, your app requests the drive relationship on the Group.
HTTP request
GET /groups/{groupId}/drive
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var drive = await graphClient.Groups["{group-id}"].Drive
.Request()
.GetAsync();
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 drive = await client.api('/groups/{groupId}/drive')
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/groups/{groupId}/drive"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
MSGraphDrive *drive = [[MSGraphDrive alloc] initWithData:data error:&nserror];
}];
[meDataTask execute];
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Drive drive = graphClient.groups("{groupId}").drive()
.buildRequest()
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
groupId := "group-id"
result, err := graphClient.GroupsById(&groupId).Drive().Get()
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Path parameters
Parameter name
Value
Description
groupId
string
Required. The identifier for the group which owns the document library.
Get the document library for a site
To access a Site's default document library, your app requests the drive relationship on the Site.
HTTP request
GET /sites/{siteId}/drive
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var drive = await graphClient.Sites["{site-id}"].Drive
.Request()
.GetAsync();
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 drive = await client.api('/sites/{siteId}/drive')
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/sites/{siteId}/drive"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
MSGraphDrive *drive = [[MSGraphDrive alloc] initWithData:data error:&nserror];
}];
[meDataTask execute];
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Drive drive = graphClient.sites("{siteId}").drive()
.buildRequest()
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
siteId := "site-id"
result, err := graphClient.SitesById(&siteId).Drive().Get()
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Path parameters
Parameter name
Value
Description
siteId
string
Required. The identifier for the site that contains the document library.
Get a drive by ID
If you have the unique identifier for a drive, you can access it directly from the top-level drives collection.
HTTP request
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var drive = await graphClient.Drives["{drive-id}"]
.Request()
.GetAsync();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/drives/{drive-id}"]]];
[urlRequest setHTTPMethod:@"GET"];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
MSGraphDrive *drive = [[MSGraphDrive alloc] initWithData:data error:&nserror];
}];
[meDataTask execute];
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Drive drive = graphClient.drives("{drive-id}")
.buildRequest()
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
driveId := "drive-id"
result, err := graphClient.DrivesById(&driveId).Get()
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Path parameters
Parameter name
Value
Description
driveId
string
Required. The identifier for the drive requested.
Optional query parameters
These method support the $select query parameter to shape the response.
Response
Each of these methods returns a Drive resource for the matching drive in the response body.
HTTP/1.1 200 OK
Content-type: application/json
{
"id": "b!t18F8ybsHUq1z3LTz8xvZqP8zaSWjkFNhsME-Fepo75dTf9vQKfeRblBZjoSQrd7",
"driveType": "business",
"owner": {
"user": {
"id": "efee1b77-fb3b-4f65-99d6-274c11914d12",
"displayName": "Ryan Gregg"
}
},
"quota": {
"deleted": 256938,
"remaining": 1099447353539,
"state": "normal",
"total": 1099511627776
}
}
Error response codes
If the drive does not exist and cannot be provisioned automatically (when using delegated authentication) an HTTP 404
response will be returned.