Sam's Microsoft Dynamics 365 Blog

Tuesday, 24 September 2019

Form Digest issue in SharePoint REST API

In this article we will discuss about SharePoint Form Digest issue in REST API. At the time of POST event in SharePoint REST API, we have to pass  "X-RequestDigest": jQuery("#__REQUESTDIGEST").val();  but it seems, some time jQuery("#__REQUESTDIGEST").val(); returns noting(undefined).



 So, in this case we can use below code to get Form Digest and can use in our JavaScript code instead of jQuery("#__REQUESTDIGEST").val();


   var hostUrl = "http://mycompany.sharepoint.com/sites/site1/SharePoint/oAuth";
   function getFormDigest() {
    $.support.cors = true;
    var _formDigest;
    $.ajax({
        url: hostUrl + "/_api/contextinfo",
        type: "POST",
        dataType: "json",

      headers: { "Accept": "application/json; odata=verbose" },
        xhrFields: { withCredentials: true },
        async: false,
        success: function (data) {
            _formDigest = data.d.GetContextWebInformation.FormDigestValue;
        },
        error: function () {
            console.log("Error Occured");
         }
    });

    return _formDigest;
   }



 Thanks for reading the article. Hope this Article will helpful for you. Cheers!!!

How to Get the Power Automate Flow Run URL Using Expressions

In many Power Automate projects, especially those involving approvals, error handling, or audit logs, it’s helpful to have a direct link to ...