Microsoft365R icon indicating copy to clipboard operation
Microsoft365R copied to clipboard

List_SharePoint_Sites() returns error 404

Open En-On-Git opened this issue 1 year ago • 27 comments

One of my users is experiencing an issue with this package when using the List_SharePoint_Sites() command. The command always returns the following error:

Using authorization_code flowWaiting for authentication in browser... Press Esc/Ctrl + C to abortAuthentication complete.Error in process_response(res, match.arg(http_status_handler), simplify) : Not Found (HTTP 404). Failed to complete operation. Message: Requested site could not be found.

Retrieving individual sites works as expected, and the user can retrieve their followed sites via Graph using the GET https://graph.microsoft.com/v1.0/me/followedSites endpoint via PowerShell and Graph Explorer.

Troubleshooting steps taken:

  • Re-installed the package.
  • Cleared the cached credentials via AzureAuth::clean_token_directory() and AzureGraph::delete_graph_login()
  • Tried running List_SharePoint_Sites with explicit app id of AzureR/Microsoft365R default Enterprise Registration.
  • Tried running List_SharePoint_Sites with explicit app id of a custom App Registration.
  • Tested https://graph.microsoft.com/v1.0/me/followedSites Graph endpoint via Graph Explorer.
  • Tested https://graph.microsoft.com/v1.0/me/followedSites Graph endpoint via PowerShell with the AzureR/Microsoft365R Enterprise Registration Application (Client) ID.

En-On-Git avatar Feb 18 '25 09:02 En-On-Git

This is likely to be a problem with the server. Wait 24 hours and see if it persists.

hongooi73 avatar Feb 20 '25 09:02 hongooi73

This is likely to be a problem with the server. Wait 24 hours and see if it persists.

The issue has been happening since November 2024 and we have tried everything to troubleshoot it. Microsoft has also helped from their end in investigating any possible Graph or user identity issues with no success (everything is fine on those ends).

En-On-Git avatar Feb 20 '25 09:02 En-On-Git

Did you create your own app ID? If so, can you show me the permissions?

hongooi73 avatar Feb 21 '25 00:02 hongooi73

Did you create your own app ID? If so, can you show me the permissions?

The error occurs the same way with the official AzureR/Microsoft365R Enterprise Application (d44a05d5-c6a5-4bbb-82d2-443123722380) and with a custom App Registration. Both applications have been given the required permissions listed in the app_registration.md guidance:

  • User.Read
  • Files.ReadWrite.All
  • Group.ReadWrite.All
  • Directory.Read.All
  • Mail.Send
  • Mail.ReadWrite
  • Sites.Manage.All
  • Sites.ReadWrite.All
  • email, profile, openid, offline_access

The user is able to retrieve the list of sites they follow when using Graph over PowerShell. Could you confirm if List_SharePoint_Sites() uses the following MS Graph endpoint?

https://graph.microsoft.com/v1.0/me/followedSites

En-On-Git avatar Feb 21 '25 08:02 En-On-Git

Yes, it uses the followedSites endpoint. This is the documentation:

https://learn.microsoft.com/en-us/graph/api/sites-list-followed?view=graph-rest-beta&tabs=http

@elipousson you probably know more about Sharepoint than me, have you had any problems with listing sites?

hongooi73 avatar Feb 21 '25 10:02 hongooi73

Yes, it uses the followedSites endpoint. This is the documentation:

https://learn.microsoft.com/en-us/graph/api/sites-list-followed?view=graph-rest-beta&tabs=http

@elipousson you probably know more about Sharepoint than me, have you had any problems with listing sites?

Does the package use the Beta endpoint or the v1.0?

En-On-Git avatar Feb 21 '25 11:02 En-On-Git

It uses the beta endpoint. You can change to the 1.0 endpoint by running options(azure_graph_api_version="v1.0")

hongooi73 avatar Feb 23 '25 02:02 hongooi73

It uses the beta endpoint. You can change to the 1.0 endpoint by running options(azure_graph_api_version="v1.0")

Thanks. We tried testing the List_SharePoint_Sites() with the V1.0 option but it still returns the same error. Any other ideas on how to troubleshoot it?

En-On-Git avatar Feb 24 '25 09:02 En-On-Git

I suspect this is something peculiar to your install. It doesn't seem like anyone else is affected.

Does this happen to everyone, or just that particular user?

You can try running just the underlying AzureGraph code, without MS365R loaded:

library(AzureGraph)
gr <- get_graph_login(tenant=*, app=*, ...)
call_graph_endpoint(gr$token, "me/followedSites")

hongooi73 avatar Feb 24 '25 12:02 hongooi73

Huh, I tried using the AzureGraph code and I wasn't able to list the followed sites. I did not get the "Requested site could not be found" error — just an "Access denied" message. My permissions are locked down in some weird ways, though, e.g. I can't use get_business_onedrive(), so I expect this is just one of those things that isn't enabled for me.

elipousson avatar Feb 26 '25 17:02 elipousson

@elipousson does the regular list_sharepoint_sites() work? The AzureGraph call may be incorrect, it's been some time since I looked at that package.

hongooi73 avatar Feb 26 '25 17:02 hongooi73

I suspect this is something peculiar to your install. It doesn't seem like anyone else is affected.

Does this happen to everyone, or just that particular user?

You can try running just the underlying AzureGraph code, without MS365R loaded:

library(AzureGraph)
gr <- get_graph_login(tenant=*, app=*, ...)
call_graph_endpoint(gr$token, "me/followedSites")

I confirmed with the user that they are able to retrieve the list of Followed Sites using the AzureGraph package directly with this snippet:

library(AzureGraph) graph <- get_graph_login() operation <- "me/followedSites" response <- call_graph_endpoint(graph$token, operation, http_verb = "GET") print(response)

The output is a list of all the SharePoint sites they follow containing site ID, Display Name, Description, and Web URL.

So something might be happening with the way the Microsoft365R package handles it?

En-On-Git avatar Mar 13 '25 10:03 En-On-Git

That should be exactly the same code that Microsoft365R uses. Does anyone else in your org have this problem, or is it just this user?

hongooi73 avatar Mar 14 '25 12:03 hongooi73

That should be exactly the same code that Microsoft365R uses. Does anyone else in your org have this problem, or is it just this user?

It affects a couple of my users. Both tried re-installing RStudio and the whole package and its dependencies, but the issue is still the same.

En-On-Git avatar Mar 14 '25 16:03 En-On-Git

Ok, but are there people for whom it works?

hongooi73 avatar Mar 14 '25 17:03 hongooi73

Yes, I have several users who can use the package just fine. The affected users experience the same issue when testing from the machine of one of the unaffected users, so it partly seems to be related to the individual user accounts (but again, not when using the AzureGraph library directly).

En-On-Git avatar Mar 16 '25 18:03 En-On-Git

In that case I don't think I can help much; I'm not an AzureAD/MS Identity expert. What you can try is to register another app ID for the package, in case there's something wonky with the existing ID.

hongooi73 avatar Mar 16 '25 20:03 hongooi73

Oh, something else to try: delete the contents of the AzureAuth cache folder, usually in c:\users\___\AppData\Local\AzureR

hongooi73 avatar Mar 18 '25 21:03 hongooi73

Oh, something else to try: delete the contents of the AzureAuth cache folder, usually in c:\users___\AppData\Local\AzureR

My user doesn't see a cache folder in that directory, only the login token files. We already tried deleting these as part of the initial troubleshooting, but it only seems to clear the cached credential and prompt for a new login on the next run of the package, with the issue persisting.

Is there any other option for troubleshooting? As a recap, the user can successfully send GET requests to the me/followedsites endpoint via Graph Explorer, Graph over PowerShell, and AzureGraph in RStudio. They receive the following error when trying to do so via AzureR: "Not Found (HTTP 404). Failed to complete operation. Message: Requested site could not be found." The user can query individual sites directly and we have tested using a custom Entra App registration as well with the same results, so an authentication issue is unlikely.

How is the error message sourced? Is it parsed directly from the API request response?

En-On-Git avatar Mar 24 '25 15:03 En-On-Git

Any updates on this? Has anyone else raised the same issue?

En-On-Git avatar Apr 24 '25 08:04 En-On-Git

I think it's just you.

You can try running AzureAuth::clean_token_directory() to make sure there's no stale tokens lying around (this is what the instruction to delete the cache folder does).

I did see something similar in an environment where the app ID wasn't authorised; running list_sharepoint_sites() resulted in a 404, while running the underlying AzureGraph function resulted in a different error. So it could be that different paths give different results, although this shouldn't happen.

Otherwise, you can create a new app registration, give it all the necessary permissions and login with that.

hongooi73 avatar Apr 26 '25 05:04 hongooi73

I'm having the same issue.

> list_sharepoint_sites()
Using authorization_code flow
Creating Microsoft Graph login for default tenant
Using authorization_code flow
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Error in process_response(res, match.arg(http_status_handler), simplify) : 
  Not Found (HTTP 404). Failed to complete operation. Message:
Requested site could not be found.

Br-Johnson avatar May 15 '25 17:05 Br-Johnson

Also having the same issue. I have previously been able to execute this operation fine in the past, and I can still successfully list sites using the AzureGraph functions.

Image

csjohns avatar May 15 '25 23:05 csjohns

Confirming that the issue is still occurring on our end as well. The app registration has been authorised and works for some of our users. The affected users have the same issue with a custom app registration.

En-On-Git avatar May 16 '25 08:05 En-On-Git

This issue began occurring for our team last week. The list_sharepoint_sites() returns a 404 error. The list_teams() works just fine. Going the AzureGraph way to call_graph_endpoint(..., "me/followedSites") also works fine. Unclear when this issue began happening for us though, but it was certainly functional in February.

rdinter-usda avatar May 21 '25 13:05 rdinter-usda

I had the same problem In my case it was because I was following 'sites' that were for 'channels' that have been deleted. The solution, for me, was to go to MS 365 - pick SharePoint, and scroll down to 'following' - unstar the ones that no longer exist.

jc-usda avatar May 21 '25 15:05 jc-usda

I had the same problem In my case it was because I was following 'sites' that were for 'channels' that have been deleted. The solution, for me, was to go to MS 365 - pick SharePoint, and scroll down to 'following' - unstar the ones that no longer exist.

Tested this with my users and confirmed it to work. It looks like the package has some trouble handling the list of Followed Sites if it includes sites that the user no longer has access to (e.g. site has been deleted or user has been removed from site).

En-On-Git avatar May 27 '25 14:05 En-On-Git