Namespace: microsoft.graph
Use this API to retrieve the contents of an item in a specific format.
Not all files can be converted into all formats.
To download the item in its original format, see download an item's contents.
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 /drive/items/{item-id}/content?format={format}
GET /drive/root:/{path and filename}:/content?format={format}
Query parameters
Parameter |
Type |
Description |
format |
string |
Specify the format the item's content should be downloaded as. |
The following values are valid for the format parameter:
Format value |
Description |
Supported source extensions |
pdf |
Converts the item into PDF format. |
csv, doc, docx, odp, ods, odt, pot, potm, potx, pps, ppsx, ppsxm, ppt, pptm, pptx, rtf, xls, xlsx |
html |
Converts the item into HTML format. |
loop, fluid, wbtx |
Name |
Description |
Authorization |
Bearer {token}. Required. Learn more about authentication and authorization. |
if-none-match |
String. If this request header is included and the eTag (or cTag) provided matches the current tag on the file, an HTTP 304 Not Modified response is returned. |
Example
GET /me/drive/items/{item-id}/content?format={format}
// 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}"].Content.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Format = "{format}";
});
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"
graphdrives "github.com/microsoftgraph/msgraph-sdk-go/drives"
//other-imports
)
requestFormat := "{format}"
requestParameters := &graphdrives.ItemItemsItemContentRequestBuilderGetQueryParameters{
Format: &requestFormat,
}
configuration := &graphdrives.ItemItemsItemContentRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
// 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").Content().Get(context.Background(), configuration)
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}").content().get(requestConfiguration -> {
requestConfiguration.queryParameters.format = "{format}";
});
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}/content?format={format}')
.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;
use Microsoft\Graph\Generated\Drives\Item\Items\Item\Content\ContentRequestBuilderGetRequestConfiguration;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestConfiguration = new ContentRequestBuilderGetRequestConfiguration();
$queryParameters = ContentRequestBuilderGetRequestConfiguration::createQueryParameters();
$queryParameters->format = "{format}";
$requestConfiguration->queryParameters = $queryParameters;
$graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->content()->get($requestConfiguration)->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
from msgraph.generated.drives.item.items.item.content.content_request_builder import ContentRequestBuilder
from kiota_abstractions.base_request_configuration import RequestConfiguration
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
query_params = ContentRequestBuilder.ContentRequestBuilderGetQueryParameters(
format = "{format}",
)
request_configuration = RequestConfiguration(
query_parameters = query_params,
)
await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').content.get(request_configuration = request_configuration)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation.
Response
Returns a 302 Found
response redirecting to a pre-authenticated download URL for the converted file.
To download the converted file, your app must follow the Location
header in the response.
Pre-authenticated URLs are only valid for a short period of time (a few minutes) and do not require an Authorization
header to access.
HTTP/1.1 302 Found
Location: https://b0mpua-by3301.files.1drv.com/y23vmagahszhxzlcvhasdhasghasodfi
Error responses
See Error Responses for more information about how errors are returned.