JSOM Anonymously CAML query list items
-
01-10-2020 - |
Question
I am attempting to query a list using CAML via JSOM and am getting the error message The method "GetItems" of the type "List" with id "{GUID}" is blocked by the administrator on the server.
I have set the web application for anonymous, the site for anonymous use, and have checked that anonymous users have View
permissions on the list, but I continue to get this error message. I have verified my CAML is correct because I get the correct return values when running under an authenticated user. I have come across some sources that say to toggle off Require Use Remote Interfaces Permission, but that didn't resolve my problem either. Any suggestions?
Solution 2
I found a solution to my problem here. You have to remove the GetItems
function from the AnonymousRestrictedTypes
via powershell. Hope this helps others with this issue.
OTHER TIPS
In On Premise environment, we can disable the “Require Use Remote Interfaces permission” to let anonymous users access Client Object Model in Central Administration.
If it is an Online environment, you can use SP.Site.updateClientObjectModelUseRemoteAPIsPermissionSetting
Method to do the trick.
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(function() {
var ctx = new SP.ClientContext();
var site = ctx.get_site();
site.updateClientObjectModelUseRemoteAPIsPermissionSetting(false);
ctx.executeQueryAsync(
function() { alert('success') },
function() { alert('error') }
);
}, 'sp.js');
</script>