Skip to content

https://mytenant.sharepoint.com/sites/dev/_api/v2.0/sites/{siteId}/lists/{listId}/items/{itemId}/preview returns an HTTP 403 every time using SPHttpClient class from an SPFx Web Part #5479

@FranckyC

Description

@FranckyC

Category

  • Bug

Describe the bug

I'm trying to use the SharePoint REST API v2.0 endpoint and especially the https://mytenant.sharepoint.com/sites/dev/_api/v2.0/sites/{siteId}/lists/{listId}/items/{itemId}/preview method to get the preview URL for a document in a SharePoint site from an SPFx Web Part just like the Microsoft Graph counterpart (HTTP POST). I'm following the documentation available here.

When using the url ../driveItem/preview and the SPHttpClient SPFx builtin class, the call returns a HTTP 403 error every time even if I have access to the underlying item.

However, using the exact same url but this time with AadHttpClient works well (HTTP 200). Here is an illustration of the issue:

issue

I precise I didn't grant any specific permissions in my SPFx package-solution.json. Not sure if this is expected since the authentication method is different between the two approaches (Bearer token vs cookie/digest).

Last but not least, the similar call ../driveItem/thumbnails for the same item (HTTP GET) using SPHttpClient works well.

Steps to reproduce

  1. In a SPFx Web Part, make a call to https://mytenant.sharepoint.com/sites/dev/_api/v2.0/sites/{siteId}/lists/{listId}/items/{itemId}/preview URL using SPHttpClient.
  2. Make the same call with AadHttpClient to see the difference.

Expected behavior

Using /_api/v2.0/sites/{siteId}/lists/{listId}/items/{itemId}/preview endpoint using SPHttpClient should returns an HTTP 200 when user has access to the element.

Developer environment

  • SPFx 1.10.0
  • Office 365 Developer tenant (not first release)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:authCategory: Authentication (Azure AD / etc)area:csom/rest/apiCategory: SharePoint Client Side Object Model SDK / REST APIstatus:to-be-reviewedIssue needs to be reviewed by Microsoft for additional follow up / review.type:archive-old-issueIssues which are closed as tool old for active work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions