I am new to Azure Functions. I am creating a function to call a SharePoint site but stuck at execute query.
Here is my code -
var password = "Somepassword";
var username = "Some login name";
var Url = "Site URL";
using (var context = new ClientContext(Url))
{
var securepass = new SecureString();
foreach (char c in password)
{
securepass.AppendChar(c);
}
log.LogInformation("C# HTTP");
SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(username, securepass);
context.Credentials = credentials;
Web web = context.Web;
context.Load(web);
log.LogInformation("web object load");
context.ExecuteQuery();
At execute query I am getting an exception -
[Information] The remote server returned an error: (400) Bad Request. [Information] at System.Net.HttpWebRequest.GetResponse() at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest() at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() at Submission#0.d__1.MoveNext() in D:\home\site\wwwroot\HttpTrigger3\run.csx:line 61 [Information] Executed 'Functions.HttpTrigger3' (Succeeded, Id=Some Id)
I don't understand what's wrong. Could anyone please help? Thanks!