SPFx in SP2016-OnPrem: Get/Post not working across web applications in same SharePoint Farm

%3CLINGO-SUB%20id%3D%22lingo-sub-1071317%22%20slang%3D%22en-US%22%3ESPFx%20in%20SP2016-OnPrem%3A%20Get%2FPost%20not%20working%20across%20web%20applications%20in%20same%20SharePoint%20Farm%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1071317%22%20slang%3D%22en-US%22%3E%3CP%3ENeed%20to%20access%20the%20list%20items%20where%20SPFX%20webpart%20is%20deployed%20in%20one%20SharePoint%202016%20application%20(%3CA%20href%3D%22https%3A%2F%2Fabc.sharepoint.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fabc.sharepoint.com%3C%2FA%3E)%20and%20list%20is%20present%20in%20another%20SharePoint%20application%20(%3CA%20href%3D%22https%3A%2F%2Fmysite.sharepoint.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmysite.sharepoint.com%3C%2FA%3E)%20in%20same%20SharePoint%202016%20server%20farm%20with%20same%20credentials.%3C%2FP%3E%3CP%3E%3CSTRONG%3ESharePoint%20version%3C%2FSTRONG%3E%3A%202016%20on-premise%3C%2FP%3E%3CP%3E%3CSTRONG%3ESPFX%3C%2FSTRONG%3E%3A%201.1%3C%2FP%3E%3CP%3E%3CSTRONG%3ETried%3C%2FSTRONG%3E%3A%20used%20%22%40pnp%2Fsp-addinhelpers%22%20and%20%40pnp%2Fsp.%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSTRONG%3ECode%3A%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eimport%20%7B%20sp%2C%20SPRequestExecutorClient%20%7D%20from%20%22%40pnp%2Fsp-addinhelpers%22%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Efunction%20getitemfromotherdomain()%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%20sp.setup(%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sp%3A%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20fetchClientFactory%3A%20()%20%3D%26gt%3B%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20return%20new%20SPRequestExecutorClient()%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Econst%26nbsp%3B%20addInWebUrl%3D%20%22%3CA%20href%3D%22https%3A%2F%2Fabc.sharepoint.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fabc.sharepoint.com%2F%3C%2FA%3E%22%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Econst%20hostWebUrl%20%3D%20%22%3CA%20href%3D%22https%3A%2F%2Fmysite.sharepoint.com%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmysite.sharepoint.com%2F%3C%2FA%3E%22%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%2F%2F%20make%20requests%20into%20the%20host%20web%20via%20the%20SP.RequestExecutor%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Esp.crossDomainWeb(addInWebUrl%2C%20hostWebUrl).get().then(w%20%3D%26gt%3B%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%20console.log(w)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20console.log(JSON.stringify(w%2C%20null%2C%204))%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D)%3B%26nbsp%3B%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3ESource%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3A%20%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fpnpjs%2Fsp-addinhelpers%2Fdocs%2Fsp-rest-addin%2F%26nbsp%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fpnp.github.io%2Fpnpjs%2Fsp-addinhelpers%2Fdocs%2Fsp-rest-addin%2F%26nbsp%3B%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3Ecalling%20the%20Function%3C%2FSTRONG%3E%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3Econst%20script1%20%3D%20document.createElement(%22script%22)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20script1.src%3D%22%2F_layouts%2F15%2FSP.RequestExecutor.js%22%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20script1.async%20%3D%20true%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20document.body.appendChild(script1)%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20getitemfromotherdomain()%3B%3C%2FSPAN%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EError%20occured%3A%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EFailed%20to%20load%20resource%3A%20the%20server%20responded%20with%20a%20status%20of%20403%20(Forbidden)%26nbsp%3B%3C%2FSPAN%3Eon%20calling%20of%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fabc.sharepoint.com%2F_api%2FSP.AppContextSite(%40target)%2Fweb%3F%40target%3D'https%3A%2F%2Fmysite.sharepoint.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fabc.sharepoint.com%2F_api%2FSP.AppContextSite(%40target)%2Fweb%3F%40target%3D'https%3A%2F%2Fmysite.sharepoint.com%3C%2FA%3E'%3C%2FP%3E%3CP%3E%3CSTRONG%3Eerror%20expanded%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CERROR%3E%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fado%2F2007%2F08%2Fdataservices%2Fmetadata%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fado%2F2007%2F08%2Fdataservices%2Fmetadata%3C%2FA%3E%22%26gt%3B%3C%2FERROR%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CCODE%3E%3CSTRONG%3E-1%2C%20Microsoft.SharePoint.SPException%3C%2FSTRONG%3E%3C%2FCODE%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CMESSAGE%3E%3CSTRONG%3EThere%20is%20no%20app%20context%20to%20execute%20this%20request.%3C%2FSTRONG%3E%3C%2FMESSAGE%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E(index)%3A1%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3EUncaught%20(in%20promise)%3C%2FSPAN%3E%3C%2FP%3E%3COL%3E%3CLI%3E%3CSPAN%3EResponse%3C%2FSPAN%3E%3COL%3E%3CLI%3E%3CSPAN%3Ebody%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3BReadableStream%3C%2FSPAN%3E%3COL%3E%3CLI%3E%3CSPAN%3Elocked%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3Bfalse%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3E__proto__%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3BReadableStream%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FOL%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3EbodyUsed%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3Bfalse%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3Eheaders%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3BHeaders%3C%2FSPAN%3E%3COL%3E%3CLI%3E%3CSPAN%3E__proto__%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3BHeaders%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FOL%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3Eok%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3Bfalse%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3Eredirected%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3Bfalse%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3Estatus%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3B403%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3EstatusText%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3B%22Forbidden%22%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3Etype%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3B%22default%22%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3Eurl%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3B%22%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E__proto__%3C%2FSPAN%3E%3CSPAN%3E%3A%26nbsp%3BResponse%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FOL%3E%3C%2FLI%3E%3C%2FOL%3E
Occasional Visitor

Need to access the list items where SPFX webpart is deployed in one SharePoint 2016 application (https://abc.sharepoint.com) and list is present in another SharePoint application (https://mysite.sharepoint.com) in same SharePoint 2016 server farm with same credentials.

SharePoint version: 2016 on-premise

SPFX: 1.1

Tried: used "@pnp/sp-addinhelpers" and @pnp/sp.

Code:

import { sp, SPRequestExecutorClient } from "@pnp/sp-addinhelpers";

function getitemfromotherdomain(){

  sp.setup({

    sp: {

        fetchClientFactory: () => {

            return new SPRequestExecutorClient();

        },

    },

});

const  addInWebUrl= "https://abc.sharepoint.com/";

const hostWebUrl = "https://mysite.sharepoint.com/";

// make requests into the host web via the SP.RequestExecutor

sp.crossDomainWeb(addInWebUrl, hostWebUrl).get().then(w => {

  console.log(w);

    console.log(JSON.stringify(w, null, 4));

});  

}

Source : https://pnp.github.io/pnpjs/sp-addinhelpers/docs/sp-rest-addin/ 

calling the Function:

    const script1 = document.createElement("script");

    script1.src="/_layouts/15/SP.RequestExecutor.js";

    script1.async = true;

    document.body.appendChild(script1);

    getitemfromotherdomain(); 

Error occured: Failed to load resource: the server responded with a status of 403 (Forbidden) on calling of

https://abc.sharepoint.com/_api/SP.AppContextSite(@target)/web?@target='https://mysite.sharepoint.co...'

error expanded:

<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">

<m:code>-1, Microsoft.SharePoint.SPException</m:code>

<m:message xml:lang="en-US">There is no app context to execute this request.</m:message>

</m:error>

(index):1 Uncaught (in promise)

  1. Response
    1. body: ReadableStream
      1. locked: false
      2. __proto__: ReadableStream
    2. bodyUsed: false
    3. headers: Headers
      1. __proto__: Headers
    4. ok: false
    5. redirected: false
    6. status: 403
    7. statusText: "Forbidden"
    8. type: "default"
    9. url: "
    10.  __proto__: Response
0 Replies