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

New Here ,
Mar 01, 2021 Mar 01, 2021

Copy link to clipboard

Copied

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.

TOPICS
How to, JavaScript, PDF forms

Views

116

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 01, 2021 Mar 01, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 01, 2021 Mar 01, 2021

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 01, 2021 Mar 01, 2021

Copy link to clipboard

Copied

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);

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 02, 2021 Mar 02, 2021

Copy link to clipboard

Copied

You can't use that code in a button. You can call it from a button but only if it is installed at the application level. Do you need to distribute these PDF files to desktops that you are not in control of? 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Yes, so I have put it in my app folder level as I have been reading about in the documentation.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Yes. If you want to use the HTTP object. But there are other ways to achieve the same thing that will work when attached to a button. You'll just need to format the response as FDF instead of JSON.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

LATEST

Ok, so I figured out how to call my getData function from within the button successfully and it prints the info i need it to in the console but this is only if the full API is added as the parameter. However, I still need to be able to rely on this.getField function to access my 'caseno' form field. So whatever Case Number is input into the 'caseno' field gets pulled and added to the end of my API string.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

I found this on stack overflow ... it seems like you are all over the internet helping us with your knowledge of Adobe!

 

I have the folder level script installed and it runs when the document opens. My new error is similar to this question where 'this.getField' is not a function. I removed my function call as was mentioned in the blog post but I am unsure how to reference my function now. When I try calling getData(fullURL) from within the button it says it is not defined. I do understand how that would be an issue, I just can not come up with the solution to reference the folder level script properly from within a button. Could you offer some assitance?

 

Thanks again for your help!

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines