9

Based on my research and this Video, I was under the impression that switching between the Graph API and the SharePoint REST API should be pretty straight forward.

  • After obtaining an OAuth2 token, I am able to access the Graph API with a call such as: https://graph.microsoft.com/v1.0/sites/root/drives.

  • However calling the SharePoint Api as documented:
    http://<my_tenant>/site/_api/lists fails with:

    {"error_description":"Invalid issuer or signature."}
    

Is a different token required for the REST API? How can I acquire it?

  • there is a authentication.asmx soap endpoint which has login method, which returns a access token that can be further used while session lasts. Will that help? – Swayam Siddha Jul 13 '17 at 9:46
  • Thank you Swayam Siddha, I tried your approach, but was unable to login with my normal credentials. Using python: from zeep import Client client = Client('https://<mysite>.sharepoint.com/_vti_bin/authentication.asmx?WSDL') client.service.Login(username='<my_user>@<mysite>.onmicrosoft.com', password='<my password>') returns: { 'CookieName': None, 'ErrorCode': 'PasswordNotMatch', 'TimeoutSeconds': 0 } And I have checked and double checked that the credentials are correct. – James Jul 13 '17 at 10:45
  • Your implementation seems alright. Cant help mate – Swayam Siddha Jul 13 '17 at 10:57
  • You should check this out: stackoverflow.com/questions/56297049/… – Haris Osmanagić May 29 at 15:55
2

As of this moment, access to SharePoint endpoint via Graph API is possible only through the beta endpoint.

Your URL should be as below:

https://graph.microsoft.com/beta/sites/tenantname.sharepoint.com/lists

Make a normal GET call to the above endpoint, the output would be as below:

enter image description here

Reference - Working with SharePoint sites in Microsoft Graph

To access the http://<my_tenant>/site/_api/lists endpoint, Graph API token wont work.

If you are logged into SharePoint you don't need any token at all to make a get request (pure client-side solution). When you make the below call, it gets the data based on your permissions.

$.ajax({
           url: "https://sitecollectionurl/_api/web/lists",
           method: "GET",
           headers: { "Accept": "application/json; odata=verbose" },
           success: function (data) {
                console.log(data);
          },
          error: function (data) {
              console.log("sowmthing went wrong: "+ data);
         }
});

Also, you can use the excellent Graph explorer to test your Graph API calls. Here, select the version as beta and you can see the data from your sharepoint lists.

Graph Explorer

-1

If there is a 401-Error on request (test in browser) the error includes detailed information about the authentication you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.