i'm using a jquery script embedded in a SharePoint page. i am able to load the results of a /_api/web/webs call to REST as myself (site collection admin). However, anyone that visits the page that is not a site collection admin (even users with Full Control access) are met with a prompt to enter their login credentials. After inputing their credentials three times, they are met with a 401 Unauthorized error.
It seems like just about any other api call works for just about all the users but specifically _api/web/webs is unauthorized.
Any information on why this particular call would require elevated privileges or if i am doing something wrong would be appreciated.
Here is the code:
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript">
var root;
$(function () {
var pathname = window.location.pathname; // Returns path only
var url = window.location.href;
root = url.substring(0,(url.length - pathname.length));
$.getScript(root + "/_layouts/15/SP.RequestExecutor.js", getWebInfo) ;
});
function getWebInfo(){
var executor = new SP.RequestExecutor(root);
executor.executeAsync({
url: root + "/_api/web/webs",
method: "GET",
headers: { "Accept": "application/json; odata=verbose"},
success: successfulCall,
error: failureCall
});
}
</script>
RequestExecutor
? That's the cross-domain library for use in an appweb. You can simply use$.ajax({url: "/_api/web/webs"});
, since you're on the same domain.