Sharepoint Online SPFx Search Rest Api 403

In case you develop an SPFx and you try to use RestApi for Search (or maybe also with the SP Rest) and you get 403, this in because your Webpart is running in his own scope, under an IFRAME.


The solution is to dynamically take your Absolute Url
    let filesQuery = this.context.pageContext.web.absoluteUrl;

Every SPFx Webpart has his own SPPageContextInfo.

P.S.
In case you choose to user SPHttpClient, you need 2 things to get over your 500 error:
1. use Default configuration (that should be v3 or v4)
2. change Accept header odata part to verbose

    this.context.spHttpClient.get(filesQuerynew SPHttpClientConfiguration({}),
      { headers: { Accept: "application/json;odata=verbose;charset=utf-8" } })  
      .then((responseSPHttpClientResponse=> {  
        response.json().then((responseJSONany=> {  
          console.log(responseJSON); 
          //your code ...
        });  
      }); 

Comments

  1. Sharepoint Online Spfx Search Rest Api 403 >>>>> Download Now

    >>>>> Download Full

    Sharepoint Online Spfx Search Rest Api 403 >>>>> Download LINK

    >>>>> Download Now

    Sharepoint Online Spfx Search Rest Api 403 >>>>> Download Full

    >>>>> Download LINK Lk

    ReplyDelete

Post a Comment

Popular posts from this blog

OverTheWire[.com] Natas Walkthrough - JUST HINT, NO SPOILERS

Asp.Net Ending Response options, Response.End() vs CompleteRequest()

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem