Forum Discussion
lucafabbri365
Aug 31, 2020Brass Contributor
SharePoint access from third party application
Hello Community,
I'm writing to ask for a question regarding SharePoint Online access from third party application.
Basically I have a third party application written in Python (on-premise) needs to access to SharePoint online (read/write documents stored in a list) via REST API (or Microsoft Graph).
- Which is the best way ? REST API or Microsoft Graph ?
- Which are supported authentication types ? (It should be a server side authentication - no client side - so a, what is called, "Service Account" is preferable.
Thank you,
Luca
- Graph is a framework, REST is the method you use to access Graph and although there are other ways to access SharePoint, I’ve found Graph to be the easiest and provides additional functionality that you can use to scale.
I’ve never done it from Python but even from C#, the Microsoft delivered packages do nothing more than call REST end points.
If you want to use a service principal, create an application in Azure and assign it the required application (not delegated) roles.
From there, start exploring the end points by using the documentation. These may help.
https://docs.microsoft.com/en-us/graph/api/resources/sharepoint?view=graph-rest-1.0#sharepoint-api-root-resources
https://docs.microsoft.com/en-us/graph/auth-v2-service
https://docs.microsoft.com/en-us/graph/api/overview?view=graph-rest-1.0
Good luck!
- BradDBrass ContributorGraph is a framework, REST is the method you use to access Graph and although there are other ways to access SharePoint, I’ve found Graph to be the easiest and provides additional functionality that you can use to scale.
I’ve never done it from Python but even from C#, the Microsoft delivered packages do nothing more than call REST end points.
If you want to use a service principal, create an application in Azure and assign it the required application (not delegated) roles.
From there, start exploring the end points by using the documentation. These may help.
https://docs.microsoft.com/en-us/graph/api/resources/sharepoint?view=graph-rest-1.0#sharepoint-api-root-resources
https://docs.microsoft.com/en-us/graph/auth-v2-service
https://docs.microsoft.com/en-us/graph/api/overview?view=graph-rest-1.0
Good luck!- gfabbriCopper ContributorHi Brad, perhaps you can help me even if this post is very old.
We have a third party application that access to our Sharepoint lits.
The code has not change in the past 4 month but til 1 month the code is not able anymore to get the lists content:
We can access to the site, the array of lists definition but when we try to get the list content is always empty (even with a simple query like get the first 10 items).
When I perform the query, is not returned any error.
I post my code below:
try
{
clientContext = new PnP.Framework.AuthenticationManager().GetACSAppOnlyContext(siteUrl, clientId, clientSecret, PnP.Framework.AzureEnvironment.Production);
clientContext.Load(clientContext.Web, p => p.Title);
clientContext.ExecuteQuery();
Console.WriteLine($"Title: {this.clientContext.Web.Title}"); //ok
ListCollection lists = clientContext.Web.Lists;
clientContext.Load(lists);
clientContext.ExecuteQuery();
foreach (List list in lists)
{
Console.WriteLine($"- {list.Title}"); //ok
}
List oList = this.clientContext.Web.Lists.GetByTitle("RichiestaAssenza");
List test = (from list in lists where list.Title == "RichiestaAssenza" select list).FirstOrDefault(); //ok
CamlQuery query = CamlQuery.CreateAllItemsQuery(10);
ListItemCollection listItemCollection = oList.GetItems(query);
this.clientContext.Load(listItemCollection);
clientContext.ExecuteQuery();
Console.WriteLine($"- {listItemCollection.Count}"); //always zero
}
catch (Exception ex)
{
throw;
}
Do you think that there is a good way to understand which could be the problem? - lucafabbri365Brass Contributor
thank you very much for useful information.
You are right, REST is an accessing method.
So as I discovered, another method is to use SharePoint REST API v1 (no Microsoft Graph) ?
Regarding authentication, if I use Service Principal with MSFT Graph, then I have to create an Azure app, but if I use SharePoint REST API v1, should I register Azure app too (link: Granting access via Azure AD App-Only) to use server-side auth. ?
Thank you again,
Luca