I can't get to the site through Microsoft graph (error 500)

Cristina Sanz Castellanos 21 Reputation points
2021-03-23T12:27:52.94+00:00

I have an online sharepoint site created and I want to get through the Microsoft graph api to the documents section in order to manage it via api. Every time I try to run the call https://graph.microsoft.com/v1.0/sites/\[siteid} it returns the following:

HTTP/1.1 500 InternalServerError
Content-Type: application/json
Transfer-Encoding: chunked
Strict-Transport-Security: max-age=31536000
request-id: f264df68-fbd3-4508-b352-5f450435997e
client-request-id: f264df68-fbd3-4508-b352-5f450435997e
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"North Europe","Slice":"E","Ring":"4","ScaleUnit":"003","RoleInstance":"DB1PEPF00005A49"}}
Cache-Control: max-age=0, private
Date: Tue, 23 Mar 2021 12:24:12 GMT
{
"error": {
"code": "generalException",
"message": "An unspecified error has occurred.",
"innerError": {
"date": "2021-03-23T12:24:13",
"request-id": "f264df68-fbd3-4508-b352-5f450435997e",
"client-request-id": "f264df68-fbd3-4508-b352-5f450435997e"
}
}
}

It is not the first time I have worked with Microsoft graph, we have already implemented it to work with calendars and we have not had much problem:

  • The application is registered in Azure, the secret is created, the permissions are granted and little else...

Do I have to do any additional steps for Sharepoint?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,250 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,810 questions
0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2021-03-24T03:02:06.027+00:00

    The 500 status code generally represents a server problem. What we can do is to check whether there is a problem with the step of calling the API. Try to call the API in the graph explorer with a user with the permission of this site to check whether the issue still exists. And this API works well when I test in graph explorer.
    If the issue still exists, I suggest you submit a ticket in the admin center with the request-id, then you could get the detailed error information.


    Updated:
    You need to use this api to get the site id:

    GET /sites/{hostname}:/{server-relative-path}  
    

    Document:Get a site resource
    Test demo for your reference:
    81248-image.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Cristina Sanz Castellanos 21 Reputation points
    2021-03-24T09:48:29.387+00:00

    Hello!

    I have tried it from the graph explorer and I get the following message: "Invalid host name for this tenant", which I do not understand because the name is correct. The call I'm using is https://graph.microsoft.com/v1.0/sites/xxxx and I can see it through the url: https://myenterprise.sharepoint.com/sites/xxxx.

    Testing it from graph explorer with my user should not be a permissions issue as I have full control of the sharepoint site

    0 comments No comments

  3. sadomovalex 3,631 Reputation points
    2021-03-24T14:15:10.467+00:00

    The call I'm using is https://graph.microsoft.com/v1.0/sites/xxxx and I can see it through the url: https://myenterprise.sharepoint.com/sites/xxxx.

    do you pass site url to Graph? If yes try to use siteId (guid) instead. You may get it e.g. via PnP powershell:
    Connect-PnPOnline -Url ...
    $site = Get-PnPSite
    $site.ID

    0 comments No comments

  4. Cristina Sanz Castellanos 21 Reputation points
    2021-03-24T16:00:48.747+00:00

    Hello, I have tried passing the name but also with the GUID which I get through the url

    https://myenterprise.sharepoint.com/sites/xxxx/_api/web/id


  5. Cristina Sanz Castellanos 21 Reputation points
    2021-03-25T08:05:37.317+00:00

    Thank you very much! indeed with the previous instructions I manage to reach the site from the graph explorer, although I still get a 500 error from my API, although I have already been able to verify that it is due to the creation of the token (using the token generated by the graph explorer my API works too).

    In the case of the application that we develop, we are using the application login and not the user, although I understand that this should not matter. Or is there any special permission that must be given in Sharepoint Online to run the API as an application? In azure I have everything related to sites and files, so I understand that the problem is not azure

    I attach the parameters that we use to generate the token, to see if you can help me:

    • tenant = obtained from azure
    • contentType = application/x-www-form-urlencoded
    • client_id = obtained from azure
    • scope = https://graph.microsoft.com/.default
    • client_secret = obtained from azure
    • grant_type = client_credentials

    In any case I will continue investigating in this line.

    Thank you very much again, I start to see the light at the end of the tunnel, jejeje.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.