Access a shared item or a collection of shared items by using a sharingToken or sharing URL.
Using the shares API allows you to access content shared with the signed in user or shared using an authenticated sharing URL.
GET /shares/{sharingTokenOrUrl}
Parameter Name | Value | Description |
---|---|---|
sharingTokenOrUrl | string |
Required. A sharing token as returned by the API or a properly encoded sharing URL. |
To encode a sharing URL, use the following logic:
- First, use base64 encode the URL.
- Convert the base64 encoded result to unpadded base64url format by removing
=
characters from the end of the value, replacing/
with_
and+
with-
.) - Append
u!
to be beginning of the string.
As an example, to encode a URL in C#:
string sharingUrl = "https://onedrive.live.com/redir?resid=1231244193912!12&authKey=1201919!12921!1";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/','_').Replace('+','-');
Do not supply a request body with this method.
This method returns an Share resource for the root of
the shared item(s). The items that are shared can be accessed using the root
relationship of the Share resource.
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "123139199abc",
"name": "shared-item.docx",
"owner": {
"user": {
"id": "123001a",
"displayName": "Daron Spektor"
}
}
}
The share resource behaves similar to the drive resource. You can access items within the share by using the items or root relationship, just like with a drive.
If only a single item is shared, instead of a collection of items, attempting to get the children of the root relationship will fail.
This example shows how to use a sharing URL to retrieve the items that have been shared.
GET /shares/{sharingTokenOrUrl}/root?expand=children
This request asks for the root item that was shared, which can either be the
shared item (when a single item has been shared) or a collection of items. By
including the ?expand=children
parameter, the result will return information
from a single call that will be useful for either single or multiple shared items.
HTTP/1.1 200 OK
Content-Type: application/json
{
"id": "191911111!11123",
"name": "OfficeProjectPlanning.docx",
"createdBy": { "user": { "id": "123001a", "displayName": "Daron Spektor" } },
"size": 11412,
"file": { }
}
Read the Error Responses topic for more information about how errors are returned.
- This API is not available for OneDrive for Business or SharePoint.