"Operation not allowed" on Graph API Item Preview endpoint

Python Developer 7 25 Reputation points
2024-05-28T06:05:54.8866667+00:00

Hello,

I have created an App registration.

Endpoint in question: https://video2.skills-academy.com/en-us/graph/api/driveitem-preview?view=graph-rest-1.0

According to that document, this endpoint requires at least "Files.Read" permission. I've requested all of these: "Files.Read.All", "Files.ReadWrite", "Files.ReadWrite.All", "Sites.Read.All", "Sites.ReadWrite.All"

After acquiring the access token, I then call the preview endpoint, like so:

https://graph.microsoft.com/v1.0/drives/{DRIVE_ID}/items/{ITEM_ID}/preview

And receive back the error

{"error":{"code":"notAllowed","message":"Operation not allowed"}}

I have tried to preview a PNG, TXT, PDF, XLSX and CSV files.

What Am I doing wrong?

User's image

Thanks!

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,253 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
939 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,151 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 39,736 Reputation points
    2024-05-28T08:31:31.92+00:00

    Hi @Python Developer 7

    Yes, it should be a POST request rather than a GET request, because it allows you to send the request body.

    By the way, the preview action is currently only available on SharePoint and OneDrive for Business, not personal OneDrive.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Python Developer 7 25 Reputation points
    2024-05-28T06:35:49.6333333+00:00

    Ah wait wait wait ... it needs a POST request, not a GET ... i've been sending GET ... I receive this now as mentioned in the docs:

    {
        "getUrl": "https://www.onedrive.com/embed?foo=bar&bar=baz",
        "postParameters": "param1=value&param2=another%20value",
        "postUrl": "https://www.onedrive.com/embed_by_post"
    }
    
    0 comments No comments