Skip to main content

Notifications

Community site session details

Community site session details

Session Id : aj8cJaRGa0VptNlKbP/1J5
Power Automate - Building Flows
Unanswered

Why does the sharepoint REST API return a different link than the one returned by the Graph API?

Like (0) ShareShare
ReportReport
Posted on 20 Apr 2024 17:04:27 by 66

I am trying to standardize Graph API with Sharepoint REST API v2.0 since the Graph explorer validates using "whatif" that the request I make can be called from Sharepoint API, but both links are totally different

 

A little context, I am trying to generate an embedded link, the Graph API generates it well and it is viewable as editable, but in Sharepoint API, although it generates the link, this message appears when I open it in the browser

 

RequestAccess.png

 

In the Graph API I use this url with the POST method and their respective headers

https://graph.microsoft.com/v1.0/sites/{siteId}/drives/{driveId}/items/{fileId}/preview

{
 "allowEdit":false,
 "viewer":"office"
}

And in Sharepoint I use the same but with this url

https://{tenantName}.sharepoint.com/{relativeUrl}/_api/v2.0/drives/{driveId}/items/{fileId}/preview

What Graph API returns is this

https://{tenantName}.sharepoint.com/sites/{relativeUrl/_layouts/15/embed.aspx?uniqueId={uniqueFileId}&access_token={token}

But Sharepoint API this

https://{tenantName}.sharepoint.com/sites/{relativeUrl}/_layouts/15/PreAuth.aspx?sourcedoc={uniqueFileId}&action=embedview#access_token={token}

Although in Graph explorer it tells me that I must leave "oneDrive.preview" at the end but in both cases it generates the link

 

The strange thing is that in Sharepoint API it returns the route with this preAuth and an access token shorter than the one returned by Graph API and I think that is why it does not show the link, a clarification, I have full access to the Sharepoint site and that the Sharepoint API link tells me that I have to request access, it is absurd, does anyone know how to fix this problem?

 

By the way, the link generated by Sharepoint API has an access time of 5 minutes, is there a way to increase that time?

 

Additionally, this link helps me to be able to view/edit within a PowerApp using a code component that uses an iFrame, it is a client requirement for the PowerApp

  • Roaby Profile Picture
    2 on 27 Jun 2024 at 09:34:46
    Re: Why does the sharepoint REST API return a different link than the one returned by the Graph API?

    Did anyone manage to find a workaround for this? The Rest API endpoint returns a different result compared to the graph API

  • MasterRA Profile Picture
    66 on 08 May 2024 at 15:13:49
    Re: Why does the sharepoint REST API return a different link than the one returned by the Graph API?

    Playing a little with the Sharepoint API, I found the solution to return the view-only url, it turns out that in the body property "viewer" you had to leave "onedrive" to be able to only view the document, while in Graph you can leave it "office" in that property when the "allowEdit" property is set to true or false, but if it is false in the Sharepoint API, if it is required to use "onedrive" to only view the document; The bad thing is that if you leave "allowEdit" in true and the "viewer" in "office", the url does not work, it asks for authorization, so I don't know what I'm doing wrong or why Sharepoint doesn't do the same thing as Graph since it is approved?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,651 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard
Loading started