7 Replies Latest reply on Aug 14, 2017 5:09 AM by Karl Heinz Kremer

    How can I connect to an API and import JSON or XML data into a form field?

    BurtonDev Level 1

      I referenced the Javascript documentation and tried using a Net.HTTP.request. The documentation only shows an example of how to do an MKCOL request, not a GET request.

       

      If I hard-code the cURL value, I get the value "undefined". If I try passing it through a variable (as in the example below), I get the error "Invalid Arguments".

       

      My code looks something like this:

       

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

                      console.println(stream);

                  }

              }

          };

          Net.HTTP.request(params);

          app.endPriv();

      });

       

      foo("http:/api.somesite.com/data?q=param&apikey=123xyz&mode=xml");

       

      (I didn't try passing data to the form yet, but just tested out the code by printing to the console first).

       

      I am assuming that the variables in the response function (msg, uri, e) are populated by the response from the server? I am not quite sure how to "grab" the data that I want, and why I am getting these errors. Also wondering if I can do it without using SOAP. Thanks in advance!