Introduction

In this post I will be talking about handling throttling in SharePoint online custom code. I had recently faced throttling issue in custom CSOM code running from a console application which was working fine with the exponential delay pattern suggestion by community to handle throttling but lately started facing some issues.


Background

For one of our client we had console application to migrate documents from network file-share to SharePoint and update the corresponding managed metadata using the client side object model. The application was designed to read the list of files to be migrated from csv then pull the file from shared file location managed by another external tool, upload new files to SharePoint and then update the corresponding metadata. All these back and forth calls to SharePoint Online breached the threshold limits set on SharePoint online tenant.

There have been few guidelines suggested by Microsoft to avoid throttling the tenant from custom code.

In this case in order to handle throttling in SharePoint online we used the exponential delay after subsequent requests in order to avoid throttling. There is Git sample which can be used to implement the exponential back off technique.

Git sample helps with

  • Implement Incremental back off and retry pattern
  • Handle http web exception code 429

Problem
After including the exponential back-off as suggested in the above Git sample application was working alright but with some recent changes in Microsoft online tenant lately connection to the site was getting terminated with an exception “Addition to this website has blocked. Please contact your administrator to resolve this problem“.



Resolution
The exception was not very helpful. Once I started looking at the http traffic logs I realized that the CSOM traffic request that was sent to SharePoint Online was undecorated.
Undecorated traffic means when there is no AppID/ App Title or User Agent string for CSOM or Rest call made to SharePoint Online.

Decorated traffic will get prioritize over the traffic which is not properly decorated, so to give priority to the request it is recommended to decorate traffic using AppID/AppTitle or User Agent string in CSOM or REST API call to SharePoint Online.

SPO request was updated to include the user agent string as below

https://gist.github.com/KanwarSingh/9cc0fe682babc537652226f846cad709.js
Another change which helped was to increase the client context request timeout property to set it to infinite.

Hope this helps with handling throttling in custom code in SharePoint Online application. Happy Coding!!

Category:
SharePoint
Tags:
,