Namespace: microsoft.graph
Get a list of driveItem objects shared with the owner of a drive.
The driveItems returned from the sharedWithMe method always include the remoteItem facet that indicates they are items from a different drive.
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.All |
Files.ReadWrite.All, Sites.Read.All, Sites.ReadWrite.All |
Delegated (personal Microsoft account) |
Files.Read.All |
Files.ReadWrite.All |
Application |
Not supported. |
Not supported. |
Note:
- A
/sharedWithMe
request succeeds with Files.Read
or Files.ReadWrite
permissions; however, some properties might be missing.
- You can't access shared items returned from this API if the request doesn't contain one of the
*.All
permissions.
HTTP request
GET /me/drive/sharedWithMe
Request body
Don't supply a request body for this method.
Response
If successful, this method returns a 200 OK
response code and a collection of driveItem objects in the response body.
By default, this method returns items shared within your own tenant. To include items shared from external tenants, append ?allowexternal=true
to a GET request.
Examples
Example 1: Get driveItems shared with me
The following example gets a collection of driveItem resources that are shared with the owner of the drive.
Request
The following example shows a request.
GET https://graph.microsoft.com/v1.0/me/drive/sharedWithMe
// 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
var result = await graphClient.Drives["{drive-id}"].SharedWithMe.GetAsSharedWithMeGetResponseAsync();
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
sharedWithMe, err := graphClient.Drives().ByDriveId("drive-id").SharedWithMe().GetAsSharedWithMeGetResponse(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);
var result = graphClient.drives().byDriveId("{drive-id}").sharedWithMe().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 sharedWithMe = await client.api('/me/drive/sharedWithMe')
.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);
$result = $graphServiceClient->drives()->byDriveId('drive-id')->sharedWithMe()->get()->wait();
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
result = await graph_client.drives.by_drive_id('drive-id').shared_with_me.get()
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
Response
The following is an example of the response that returns items shared with the signed-in user, because the drive is the user's default drive.
HTTP/1.1 200 OK
Content-Type: application/json
{
"value": [
{
"id": "1312abc",
"remoteItem": {
"id": "1991210caf!192",
"name": "March Proposal.docx",
"file": { },
"size": 19121,
"parentReference": {
"driveId": "1991210caf",
"id": "1991210caf!104"
}
}
},
{
"id": "1312def",
"remoteItem": {
"id": "1991210caf!1991",
"name": "Team Roster.xlsx",
"file": { },
"size": 37619,
"parentReference": {
"driveId": "1991210caf",
"id": "1991210caf!104"
}
}
},
{
"id": "1312ghi",
"remoteItem": {
"id": "987def!654",
"name": "January Service Review.pptx",
"file": { },
"size": 145362,
"parentReference": {
"driveId": "987def",
"id": "987def!321"
}
}
}
]
}
The following example shows how to access metadata about the shared driveItem with the name January Service Review.pptx
that requires a request using the driveId of the parentReference within the remoteItem object.
Request
The following example shows a request.
GET https://graph.microsoft.com/v1.0/drives/987def/items/987def!654
// 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
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].GetAsync();
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
items, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").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);
DriveItem result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").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 driveItem = await client.api('/drives/987def/items/987def!654')
.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);
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->get()->wait();
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
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').get()
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
Response
The following example shows the response.
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "987def!654",
"name": "January Service Review.pptx",
"file": { },
"size": 145362,
"parentReference": {
"driveId": "987def",
"id": "987def!321"
}
}