I recently had a question and how to connect to the REST web api using c# and it gave a hard time trying to connect, documentation does not give any clue how to use the rest web api(code) but community forums does, but in the code there is a CSOM nugget that seems to handle the negotiation when requests are made code below.

        var s = new System.Security.SecureString();
        "123abc".ToList().ForEach(o => s.AppendChar(o));
        SharePointOnlineCredentials cred = new SharePointOnlineCredentials("[email protected]", s);
        HttpWebRequest endpointRequesta = (HttpWebRequest)HttpWebRequest.Create("https://test.sharepoint.com/sites/CRM/_api/contextinfo");
        endpointRequest.Method = "GET";
        endpointRequest.Accept = "application/json;odata=verbose";
        endpointRequest.Credentials = cred; //<-- Notice this
        endpointRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
        HttpWebResponse endpointResponse1 = (HttpWebResponse)endpointRequest.GetResponse();

my questions are

  • Here it's using SharePointOnlineCredentials Object from CSOM ¿Why can't I use System.Net.NetworkCredential("[email protected]", "123abc")(basic Auth)? well I can use it but it raise an error 401 but with SharePointOnlineCredentials runs well. but ¿why?

  • So it make me think then that I'm forced to use .net or C# for calling this sharepoint REST Apis ¿What if i just need to call this rest api as normal webservice with any languaje?


3 Answers 3


SharePoint Online uses claims based authentication, basic Auth would not work for SharePoint Online.

You could refer to here for more: Make a RESTful API Call to SharePoint Online from Console program


It depends on what tools you will use to connect to SharePoint,

Either of below you can use to connect,

  1. PowerShell : There is a list of command lines ready to use, we have sp powershell and pnp
  2. SharePoint rest api , 1 option if you intend to connect via client side browser

Hope it helps! Happy SharePointing!


PNP will (should) make your live a lot easier ? I use PNP js, but there is a nuget package for C#. If that works as the .js modules work it's quite easy to connect to SharePoint https://github.com/pnp/pnpcore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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