An error message appears in the document content when viewing or downloading it using the Graph API

nandhini.dhandapani@triyam.com 0 Reputation points
2024-08-29T11:06:34.6633333+00:00

Hi Team,

We are using the Graph API to view and download PDFs from a .doc format. However, an error message appeared in the document content during the viewing/downloading process. We are unable to share the original document because it contains PHI data. We have shared the screenshot and error content for your reference.

Error message as "Error! Reference source not found"

image

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,820 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yakun Huang-MSFT 4,005 Reputation points Microsoft Vendor
    2024-08-30T09:08:06.3433333+00:00

    Hi @nandhini.dhandapani@triyam.com

    According to the documentation, if you download a file in a JavaScript application, Microsoft Graph will redirect it with 302, but due to the CORS policy, the browser will reject the redirect, resulting in an error that the resource cannot be found.

    So when you download a file, first make a request that includes the @microsoft.graph.downloadUrl property:

    GET /drive/items/{item-ID}?select=id,@microsoft.graph.downloadUrl
    

    And then file could be downloaded by marking another request for the Url provided in @microsoft.graph.downloadUrl property.

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.