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.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.

  • 1
    Beside the part about context, if you just want to query the current user you can just query against /_api/web/CurrentUser, e.g., $.get('/sites/eirik/_api/web/CurrentUser', function(d) { console.log($('Email', d).text()); });
    – eirikb
    Commented Apr 4, 2014 at 9:28

1 Answer 1


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..

  • 2
    For apps when you want to use an app context with REST use SP.AppContextSite, e.g., $.get("/_api/SP.AppContextSite(@target)/web/title?@target='http://localhost/sites/test'",function(d) { console.log(d); });
    – eirikb
    Commented Apr 4, 2014 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.