Skip to main content
Known Participant
March 1, 2021
Question

Pulling JSON data from a third party web API to fill PDF's form fields

  • March 1, 2021
  • 1 reply
  • 5821 views

I have an active Web API that I want to refernce in my script within Adobe Acrobat so that I can pull data from and populate the form fields in my document. I have read around and saw similar questions on these forums but nothing that matched my need or even worked for me. Any help in this area? Thanks in advance.

This topic has been closed for replies.

1 reply

Joel Geraci
Community Expert
Community Expert
March 1, 2021

It's possible but non-trivial. How much JavaScript experience do you have?

Known Participant
March 1, 2021

Thanks for your response. I am fairly confident in my JS abilities. I actually just got this code working which I saw parts of referenced somewhere else on this site and managed to stitch together to fit my need. However, it only works when run in the console, but I am attempting to add this to 'Run a Javascript' under the button option so when a user enters a specific Case Number it will pull from the API which sends back data in a JSON object and I can go forward with auto populating the other form fiels. Again, I am successfully getting the JSON object logged to the console but ONLY when running this script in the console. When I add this same code to 'Run a Javascript' button I recieve the error: SOAP.stringFromStream(stream) is not a function.

Known Participant
March 1, 2021
var API = "https://...{path}..CaseNum="
var caseno = this.getField("caseno");

var fullURL = API + caseno;


var getData = app.trustedFunction(function (cURL) {

    app.beginPriv();

    var params = {

       cVerb: "GET",

       cURL: cURL,

       oHandler: {

            response: function (msg, uri, e) {

                var stream = msg;

                var string = "";

                string = SOAP.stringFromStream(stream);

              console.println(string);
              var data = eval("(" + string + ")"); 
              console.println(data.caseNumber);
              
            }
        }
    };

    Net.HTTP.request(params);

    app.endPriv();

});

getData(fullURL);