2
votes

I am unable to execute CSOM code as Azure function timer job and I am getting 400 bad request error after executing Execute query statement. The code was executing as console app without any errors

Here I am not creating and deploying the app through visual studio. I am directly executing the code in Azure itself in timer function in the file run.csx, here I am doing normal authentication without passing access token and using SharePoint online credentials statement by passing the hardcoded username and securestring password and facing the issue.

Stack trace

2018-10-08T20:56:17  Welcome, you are now connected to log-streaming service.
2018-10-08T20:56:38.007 [Information] Executing 'Functions.ExpiredSLAIdentifier' (Reason='This function was programmatically called via the host APIs.', Id=36f36c56-ac48-4220-bcc4-040658d77fa2)
2018-10-08T20:56:42.685 [Information] Azure Function Exception:    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.Run(TimerInfo myTimer, ILogger log) in D:\home\site\wwwroot\ExpiredSLAIdentifier\run.csx:line 25
2018-10-08T20:56:42.702 [Information] Executed 'Functions.ExpiredSLAIdentifier' (Succeeded, Id=36f36c56-ac48-4220-bcc4-040658d77fa2)
1
Possible fix: Set Azure Function Version Runtime to V2Hackerman
Thanks for replying @Hackerman. It's already using runtime V2. Runtime version: 2.0.12115.0 (~2)sid1385

1 Answers

2
votes

Runtime version was set as ~2 by default when the Function App was created. That should not be used. It should be V1.

Runtime version: 1.0.11959.0 (~1)

This rectified the issue.