question

Gamze-7876 avatar image
0 Votes"
Gamze-7876 asked saldana-msft edited

About Microsoft Graph API Get OneDrive Word File Content

Hi guys,

I am using Microsoft Graph Api for create, upload and download docx/doc document on OneDrive. But I want to reach only content inside the uploaded document or existing document in OneDrive. I tried the get item and download services with Postman, Graph Explorer website and java code. But the servces didn't return the only content. Could you help me about this?
if anyone has tried it before.

(The response result can be base64 or even binary, enough to return :) )

sharepoint-devmicrosoft-graph-identitymicrosoft-graph-filesmicrosoft-graph-query-parameters
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ShivamDhiman-1582 avatar image
0 Votes"
ShivamDhiman-1582 answered Gamze-7876 edited

Hi @Gamze-7876

To get the content of your word file, locate that file in OneDrive using this endpoint.

 GET /me/drives/{drive-id}/root/children

Now get the items-id(word file id) from the response and put it in below endpoint in Postman to get the content of your word file.

 GET /drives/{drive-id}/items/{item-id}/content

Note: Response for this API https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/content does not come in Graph Explorer due to CORS policy. Please use Postman(API client) to execute this request

You can refer to this documentation for more details

Hope this helps.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment".

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @ShivamDhiman-1582 ,

Firstly thanks for your answer.

I tried the https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/content this request on Postman. But it is not working(Postman said:UnknownError)
then I tried this type: https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/:content

The second one is worked but this time the response give me @odata.context, web url, eTag, id etc. I only want to inside the data of document. Because If I get the data, I update the document content on my local services. Is it possible?

0 Votes 0 ·

Hi @Gamze-7876

As you can see I am able to get desired result by using this Graph API endpoint GET /drives/{drive-id}/items/{item-id}/content
197414-content1.png

So can you please share a screenshot of your postman with error/status code.

0 Votes 0 ·
content1.png (124.8 KiB)
Gamze-7876 avatar image Gamze-7876 ShivamDhiman-1582 ·

Hi @ShivamDhiman

I looked at the your screeshot then tried again with Postman. And It worked. I get the response similar with yours. (I guess first time there was a problem about my document.)
Thank you again.

0 Votes 0 ·
Show more comments