Does anyone has used Sharepoint Rest API, I need to develop a component "PLUGIN" that automates that task for uploading fles to Sharepoint,
all examples I found uses Other Microsoft Libraries like "Microsoft.SharePoint.Client"(CSOM) so in plugins there is not way of using those libraries in Dynamics Online, maybe you could merge them but that would be like not supported, so Sharepoint seems to expose a REST API but I'm unable of consuming that.
this is what you could find on google but a 401 error rises.
HttpWebRequest endpointRequest = (HttpWebRequest)WebRequest.Create($"{siteurl}/_api/web/lists");
var s = new System.Security.SecureString();
"abc123".ToList().ForEach(o => s.AppendChar(o));
HttpWebRequest endpointRequesta = (HttpWebRequest)HttpWebRequest.Create("https://test.sharepoint.com/sites/CRM/_api/contextinfo");
endpointRequest.Method = "GET";
endpointRequest.Accept = "application/json;odata=verbose";
NetworkCredential cred = new System.Net.NetworkCredential("admin@trainee4.onmicrosoft.com", s);
endpointRequest.Credentials = cred;
endpointRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
HttpWebResponse endpointResponse1 = (HttpWebResponse)endpointRequest.GetResponse();
by the way in line 8 if I do something like this it works
SharePointOnlineCredentials cred= new SharePointOnlineCredentials("admin@test.onmicrosoft.com", s); endpointRequest.Credentials = cred;
¿So whats the wrong with that? It Uses the Client CSOM - Microsoft.SharePoint.Client
any example, references links ?
Update 1: I can't use Power Automate.
Update 2: SPO(SharePoint Online) uses "Claims base authentication" so basic auth won't work, will do if uses either SharePointOnlineCredentials or custom implementation Custom claims with cookies, thats it's why it works.
Update 3: Maybe this it's well known but in Sharepoint Online it's recommended the use of an App(SharePoint Add-in) Create and Add-in , I think for this cases (I mean were I can't use PowerAutomate) it's better use that, where it provides the AppID, ClientId and Secret. I'll do it and share some thougths
thanks, Regards.
Hi,
Please check the below blog posts:
https://ajitpatra.com/2020/01/06/d365-call-sharepoint-api-from-plugin-custom-workflow-c-part-1/
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,522 Super User 2024 Season 2
Martin Dráb 228,441 Most Valuable Professional
nmaenpaa 101,148