OL Learn

POST Command to API


I have a hybrid mail application which I want to submit files with a POST command and also issue a POST command to see how many items are queued up. I have very limited experience in calling API’s but someone has tested the API and said they can connect and issue the command:

Post command
“username”: “admin”



"data": {
    "count": 10,
    "categories": {
        "DRAFT": 0,
        "HANDLED": 0,
        "ERROR": 3,
        "REJECTED": 0,


Where do I begin with doing this in workflow? I’m wanting to take the returned JSON and send a email out detailing how many items are PENDING_DELIVERY



You’ll have to use a script for that. Here’s a basic version that issues a POST request and writes the response to the current job file (thereby replacing it) in Workflow:

// Initialize a few objects
var xhr = new ActiveXObject("Microsoft.XMLHTTP");
var fso = new ActiveXObject("Scripting.FileSystemObject");

var payload = {
   "username": "admin"
// specify the proper URL for the API call
xhr.open("POST", "http://someUrl.example.com/ApiEndpoint", false);
// send the payload object

// check if the call was successful
if(xhr.status==200) {
  res = xhr.responseText;
  // Overwrite Workflow's Job file with the response from the API call
  var myFile = fso.CreateTextFile(Watch.GetJobFileName());

You’ll probably have to tweak this a little, but it should get you going.

thanks Phil that’s perfect