I have a requirement where I have to perform CRUD operation on SharePoint 2016 List and Libraries using the REST API from JavaScript. The problem is the application from where I need to make the calls is a .net application outside of SharePoint and is not even in the same server. I am aware of SharePoint REST API and have used it but with SharePoint. I have no idea how to use it outside of SharePoint. When I am trying to make the calls to SharePoint site it showing the Error 404 unauthorized because I am not able to authenticate the current user which was not required within the SharePoint.
If this is possible please help me to solve the problem and if possible please attach a code snippet. And if it is not possible what will be the recommended way to perform the CRUD operation on SharePoint List/Library from outside SharePoint. For e.g. creating a .net web api or something like that
Any help would be appreciated.
Issue Updated
So it all has boil down to this. I have a page(in any language but outside sharepoint) and a Javascript file linked to it. Is there any possible way to perform SharePoint Operation from it.
var url = "https://mysite.sharepoint.com" + "/_api/web/currentuser";
$.ajax({
url: url,
headers: {
Accept: "application/json;odata=verbose"
},
async: false,
success: function (data) {
var items = data.d;
console.log("Login Name: "+items.LoginName);
console.log("Email: " + items.Email);
console.log("ID: "+items.Id);
console.log("Title: "+items.Title);
},
error: function (jqxr, errorCode, errorThrown) {
console.log(jqxr.responseText);
}
});
When I run this code it gives me two errors 1. 401 Unauthorised 2. No 'Access-Control-Allow-Origin' header is present on the requested resource.
But this code is tried and tested in SharePoint Environment and it works fine. So is there any way I can run the above code from JavaScript otherwise the basic fundamentals of Rest Api fails here.