Hi all,
I am pulling a list of subsites by using the following code in a Script Editor Web Part. The problem is that if a user does not have access to one of the sites, it fails on the entire output, and displays "Forbidden" instead of just trimming out the site from the list that the user does not have access to. I need to display a list of sites that the current user has access to. I believe this may be in how I am either calling the REST API or my JavaScript. Any clues? Is there a CurrentUser call that can be added to the REST API?
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script><script type="text/javascript"> $(document).ready(function ($) { var basePath = "https://yourcompany.com/projects/_api/"; $.ajax({ url: basePath + "web/webs", type: "GET", headers: { "Accept": "application/json;odata=verbose" }, success: function (data) { //script to build UI HERE $.each(data.d.results,function(index,value){ $("#SiteList").append("<p>" + "<a href='" + value.Url + "'>" + value.Title + "</a></p>"); }); }, error: function (data) { //output error HERE alert(data.statusText); } }); });</script><style> #SiteList { border: 3px coral solid; } #SiteList h2 { color:#333; margin-bottom:10px; } </style><div id="SiteList"><h2>Projects List</h2></div>
Personal Blog: http://thebitsthatbyte.com