SlavaG
SlavaG

Reputation: 540

Sharepoint Online REST API System.UnauthorizedAccessException when trying to get SiteGroup/Users

I'm trying get SiteGroup/Users from Sharepoint Online, by calling this REST API: /_api/web?$expand=webs,lists,AllProperties,ThemeInfo,SiteUsers,SiteGroups,SiteGroups/Users,RoleDefinitions&$select=*

While on some customers sharepoint sites it's works fine , on other it's failing with :

{"error":{"code":"-2147024891, System.UnauthorizedAccessException","message": 
{"lang":"en-US","value":"Access denied. You do not have permission to perform 
this action or access this resource."}}}

When I remove SiteGroups/Users it's working fine, but I need SiteGroups/Users. In both cases user that I'm accessing with is Site collection Admin. So, I'm trying to understand what can be difference between admins that in one case works fine but in another not. Thanks

Upvotes: 2

Views: 5109

Answers (1)

Kartik Pareek
Kartik Pareek

Reputation: 23

This is Occur because you have done app registration on wrong url for example if your SharePoint File base Url is https://yourtenantname.sharepoint.com/sites/yourfoldername then Use this url for App registration https://yourtenantname.sharepoint.com/sites/yourfoldername/_layouts/15/appregnew.aspx not this https://yourtenantname.sharepoint.com/_layouts/15/appregnew.aspx.

You could refer to this article to register you app for rest API: https://anoopt.medium.com/accessing-sharepoint-data-using-postman-sharepoint-rest-api-76b70630bcbf

Upvotes: -1

Related Questions