Home

Cross-domain request in SPFx

%3CLINGO-SUB%20id%3D%22lingo-sub-760001%22%20slang%3D%22en-US%22%3ECross-domain%20request%20in%20SPFx%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-760001%22%20slang%3D%22en-US%22%3E%3CP%3EHow%20can%20I%20make%20a%20cross-domain%20request%20in%20a%20Client%20Side%20Web%20Part%20built%20with%20the%20SharePoint%20Framework%3F%20My%20need%20is%20to%20access%20SharePoint%202016%20data%20from%20a%20SharePoint%202016%20site%20in%20another%20domain%20(same%20credentials).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20found%20a%20crossDomainWeb%20method%20in%20the%20documentation%20for%20the%20add-in%20model%2C%20but%20nothing%20for%20SPFx.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-760001%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESPFx%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-762130%22%20slang%3D%22en-US%22%3ERe%3A%20Cross-domain%20request%20in%20SPFx%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-762130%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F29417%22%20target%3D%22_blank%22%3E%40Christophe%20Humbert%3C%2FA%3E%26nbsp%3BSharePoint%202016%20doesn't%20provide%20an%20easy%20way%20to%20configure%20CORS%20to%20allow%20for%20cross-domain%20calls.%20Easiest%20way%20in%20my%20experience%20is%20to%20create%20a%20custom%20Web%20API%20to%20perform%20and%20expose%20the%20SharePoint%20operations%20required%20and%20host%20it%20in%20the%20domain%20where%20your%20SPFx%20components%20reside.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-767167%22%20slang%3D%22en-US%22%3ERe%3A%20Cross-domain%20request%20in%20SPFx%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-767167%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F29417%22%20target%3D%22_blank%22%3E%40Christophe%20Humbert%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20use%20the%20Dev%20PnP%20JS%20library%20in%20SPFx%20to%20make%20cross-site%20collection%20calls.%26nbsp%3B%3CBR%20%2F%3EThe%20setup%20is%20very%20straight%20forward%20and%20will%20help%20you%20with%20other%20complex%20REST%20API%20calls%20as%20well.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fpnp.github.io%2Fpnpjs%2Fdocumentation%2Fgetting-started%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fpnp.github.io%2Fpnpjs%2Fdocumentation%2Fgetting-started%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-JS-Core%2Fwiki%2FConfiguration%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-JS-Core%2Fwiki%2FConfiguration%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F123989iF81BD131E5A24118%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22example1.png%22%20title%3D%22example1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent Contributor

How can I make a cross-domain request in a Client Side Web Part built with the SharePoint Framework? My need is to access SharePoint 2016 data from a SharePoint 2016 site in another domain (same credentials).

 

I found a crossDomainWeb method in the documentation for the add-in model, but nothing for SPFx.

2 Replies
Highlighted

@Christophe Humbert SharePoint 2016 doesn't provide an easy way to configure CORS to allow for cross-domain calls. Easiest way in my experience is to create a custom Web API to perform and expose the SharePoint operations required and host it in the domain where your SPFx components reside. 

 

Highlighted

@Christophe Humbert 

You can use the Dev PnP JS library in SPFx to make cross-site collection calls. 
The setup is very straight forward and will help you with other complex REST API calls as well. 

 

https://pnp.github.io/pnpjs/documentation/getting-started/

https://github.com/SharePoint/PnP-JS-Core/wiki/Configurationexample1.png