Office365-REST-Python-Client icon indicating copy to clipboard operation
Office365-REST-Python-Client copied to clipboard

Using Sharepoint with Graph API

Open adambenali opened this issue 3 years ago • 2 comments

Hi,

Is it possible to use the Graph API for Sharepoint? Does ClientContext.with_access_token work to authenticate, and what parts of the Graph API are supported?

Otherwise, is there a plan to add support for Sharepoint Graph API?

adambenali avatar Jul 13 '22 08:07 adambenali

I would also be interested in knowing this.

I am moving from basic auth to Azure service principal using certificates and I am having problems (403) with the lib after changing the authentication method to with_client_certificate. I believe that all the permissions were granted to my principal in sharepoint admin, so I am not sure what it's happening. Also, using the same details to authenticate in the MS graph examples works just fine.

@vgrem sorry for pinging you - but can we use graph for sharepoint? Or, would you know by any chance what could cause the error requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://xxxx.sharepoint.com/sites/xxxxx/_api/Web/getFolderByServerRelativeUrl('General')/Folders by only changing the authentication method? Thank you!

nmduarte avatar Jul 16 '22 23:07 nmduarte

I've also switched to Azure service principal and can access token with saml. ClientContext.with_access_token is not working for me. @nmduarte @adambenali Have you guys had any luck on this?

jalvarezabbott avatar Sep 16 '22 00:09 jalvarezabbott

Greetings,

when working with SharePoint API both SharePoint and SharePoint with Microsoft Graph APIs are supported, namely:

Get a file properties via SharePoint API

ctx = ClientContext(test_team_site_url).with_credentials(client_credentials)
file_url = 'Shared Documents/Report.xlsx'
file = ctx.web.get_file_by_server_relative_url(file_url).get().execute_query() 

Get a file properties via SharePoint API with Microsoft Graph

from office365.graph_client import GraphClient

client = GraphClient(acquire_token_by_client_credentials)
file_path = "Shared Documents/Report.xlsx"
file = client.users[user_id].drive.root.get_by_path(file_path).get().execute_query()

vgrem avatar Sep 18 '23 11:09 vgrem

@nmduarte, regarding:

can we use graph for SharePoint

definitely, please refer examples section which demonstrates how to use SharePoint API with Microsoft Graph.

In terms of 403 Client Error: Forbidden error when using with_client_certificate method, perhaps it was similar to this issue, anyway nowadays it has resolved.

vgrem avatar Sep 18 '23 11:09 vgrem