Monday, 22 August 2016

Making a POST request to SharePoint from an SPFx webpart

This post has been updated on 22 Jan 2017 for SharePoint Framework RC0

Following up on my previous post First SPFx webpart: Get/Set a single value userprofile property in SharePoint, in this post I have separately documented how to make an HTTP POST request from your SPFx webpart. There are lots of posts out already which show you how to make a GET request so I will not cover that here. It is fairly straightforward once you understand all the moving parts.

Import the necessary modules in your SPFx webpart code:

Now, the code which makes a POST request to create a list:

And my "Developer workbench" list is created:

Hope this helps.


SA said...

Hi Vardhaman, When I try to use the code. I receive CORS exception in IE for REST api ? Did you get into these issues

Vardhaman Deshpande said...

Hi SA,

It seems to work fine for me on IE11. Are you trying to make a request to a different domain?