Topic Options
#57188 - 08/14/19 04:19 PM API calls
Sami786 Offline
OL Expert

Registered: 01/29/14
Posts: 344
Loc: Home
Hi, I have a question that I never faced before until now, so I need your guidance!

API calls?
My client would be looking to send data via API calls. And I am wondering the feasibility of us converting API call data into a flat file so we can program in Planet Press.

Is this the same as Input SOAP plug-in?
In how many ways using PP can we access client API to retrieve data?


Edited by Sami786 (08/14/19 04:20 PM)

#57190 - 08/15/19 10:32 AM Re: API calls [Re: Sami786]
Raphael Lalonde Lefebvre Offline
OL Expert

Registered: 10/14/05
Posts: 4954
Loc: Objectif Lune Montreal
Hi Sami,

If by API call you mean REST calls, it's not the same as SOAP, and the SOAP plugin won't work for REST APIs. Unfortunately, we don't have a plugin for REST, so your only solution is to use a script.

Best I can give you is an example of such a script. In one of my latest projects, I did REST calls in a Run Script using the XMLHTTP object. Here's an example of a script that can be used for this:

var xhttp = new ActiveXObject("Microsoft.XMLHTTP");"PUT", "", false);
xhttp.setRequestHeader('Header1', 'application/json');
xhttp.setRequestHeader('Header2', Watch.GetVariable('MyVariable'));
xhttp.send("Your data");
Watch.Log(xhttp.responseText, 2);
Watch.SetVariable("APIResponse", xhttp.responseText);

First, you create the xhttp object. Then, you enter the URL of your API, as well as the request type (in this case, "PUT", but there are others like "GET" or "POST", depending on what you require). Then you can set request headers if needed, which contains parameters that may be required by your API. And after that, you use "send" to send the data. If everything is done correctly, you should receive a response from the API, and in this case, we store it in a variable.

Obviously, you'll need to change the headers and adjust the data you send based on the API's requirements, so you'll have to tweak the script.

Hope that helps!

Raphaël Lalonde-Lefebvre