Another great day!
I’ve some Azure App Service and Azure Web Job which, using Sharepoint CSOM or calling the SharePoint REST API, perform a lot of operation (batch or real-time) on SharePoint Online data.
My jobs are running since some year without any problem.
Yesterday (6 feb 2018) some of my artifacts crash unexpectedly with a strange error:
System.Net.WebException: The remote server returned an error: (429).
TOO MANY REQUESTS
Then I found a nice article that explains how avoid this error communicating with SharePoint Online
In short words you must tell to SharePoint who you are, setting the request UserAgent header with a string like this:
Identify as ISV and include Company Name, App Name Separated by a pipe character and then adding Version number separated with a slash character
Identify as NONISV and include Company Name, App Name separated by a pipe character and then adding Version number separated with a slash character
In my case, this is an Enterprise application and I had to set the UserAgent with a string like this for every call to SharePoint services.
Some of my services works using SharePoint CSOM, other, latest, the SharePoint REST API using HttpClient: here the 2 way to set this parameter for both my cases.
context.ExecutingWebRequest += delegate (object sender, WebRequestEventArgs e)
e.WebRequestExecutor.WebRequest.UserAgent = "NONISV|zSiS|MyService01/1.0";