Question

I know that in SharePoint 2013 with JavaScript, you can load the current context like so...

var context = SP.ClientContext.get_current();
var user = context.get_web().get_currentUser();
context.load(user);
context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);

But, is there a way to do this through a Web API rest call for SharePoint 2013? Ideally I would just like to be able to load/get the current context with a

$.ajax() call.

Was it helpful?

Solution

No that is not possible, you need to understand what a context really is.. when you are running the JavaScript code, it resides within a page/app.. which is SharePoint based.. and thus has the context of what contains it..

The server side code SPContext.Current again has the context because it resides within SharePoint..

Or when you are using Client Object Model, you actually give the URL and get the context.. Its just not possible with Rest APIs.. If you want a context you can alternatively use Client Object Model with C#..

Rest APIs are meant to connect from EXTERNAL devices..

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top