6 Replies Latest reply on Nov 30, 2015 2:24 PM by twelvetens

    Insert from URL and Javascript

    twelvetens

      Hi,

       

      I'm just trying to get my head around something that's probably pretty simple for those in the know.

       

      I'm trying to run some javascript using the Insert From URL script step, to return a signature for an API authorisation request.

       

      The javascript is:

       

      <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha1.js"></script>
      <script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>
      <script type="text/javascript">

         function CalculateSig(stringToSign, privateKey){
         var hash = CryptoJS.HmacSHA1(stringToSign, privateKey);
         var base64 = hash.toString(CryptoJS.enc.Base64);
         return encodeURIComponent(base64);
         }

         var d = new Date,
        expiration = 3600 // 1 hour,
        unixtime = parseInt(d.getTime() / 1000),
        future_unixtime = unixtime + expiration,
        publicKey = "1234",
        privateKey = "abcd",
        method = "GET",
        route = "forms/1/entries";

        stringToSign = publicKey + ":" + method + ":" + route + ":" + future_unixtime;
        sig = CalculateSig(stringToSign, privateKey);
        console.log(sig);
      </script>


      ... which is all pulled from the Gravity Forms Web API documentation....

      https://www.gravityhelp.com/documentation/article/web-api/

       

      I'd like to get the above to return the singature for the API session when I enter in my public and private key. Is this even possible? Am I barking up the wrong tree? I was hoping I could use InsertFromURL to populate a field with the result, which would be the signature...