HTTP Track Simulate


This endpoint will accept a JavaScript Track definition, and a sample Drop object, and return the resulting (transformed) Drop. The response also includes helpful debugging information. The Track being simulated is not persisted on flowthings.io.

Required Fields


drop
The sample Drop object. See HTTP Drop Create for details on the Drop format
js
A javascript function that takes a Drop matching the filter from the source Flow as its first argument and then returns a Drop to be written to the destination Flow. The API may be accessed from within the js in order to enhance Drops with data from other Flows by utilizing Flow.js

Request


POST https://api.flowthings.io/v0.1/<account_id>/track/simulate

Headers

NameDescription
Content-Typeapplication/json
X-Auth-TokenAuthentication Token

Example

  {
    "drop" : {
      "elems" : {
        "a" : 1
        }
    },
    "js" : "function (input_drop) {
              var a = input_drop.elems.a.value;
              input_drop.elems.b = a  * 3;
              return input_drop;
            }"
  }

Response


HTTP Codes

CodeDescription
201Resource Created
400Bad Request
401Unauthorized
503Service Unavailable

Simulator Output

The simulator output will contain a list of the Drops that were generated (if any), as well as a log, which is a list of the variables of your running script on each line number in the order they were executed (variables that are unchanged will not be reprinted).

With the request as written above, at line 2 the log shows the value of the variables "input_drop" and "a". On line 3 the log shows that the value of "input_drop" has changed:

  {
  "head" : {
    "status" : 200,
    "ok" : true,
    "messages" : [ ],
    "errors" : [ ],
    "references" : { }
  },
  "body" : {
    "drops" : [
      { "elems" : { "a" : 1, "b" : 3.0 } }
    ],
    "log" : [ {
      "a" : 1,
      "line_no" : 2,
      "input_drop" : {
        "elems" : {
          "a" : { "type" : "integer", "value" : 1 }
        }
      }
    }, {
      "line_no" : 3,
      "input_drop" : {
        "elems" : {
          "a" : { "type" : "integer", "value" : 1 },
          "b" : 3
        }
      }
    } ],
    "errors" : [ ]
  }
}

Logging statements in the form of console.log(msg) will appear in the log in the order they were executed. Changing the input javascript to

{
  "js" : "function (input_drop) {
     var a = input_drop.elems.a.value;
     console.log('before setting the value of b');
     input_drop.elems.b = a  * 3;
     return input_drop;
   }"
}

gives the output :

{
 "body" : {
    "drops" : [
      { "elems" : { "a" : 1, "b" : 3.0 } }
    ],
    "log" : [
      { "line_no" : 2 },
      {"console" : "before setting the value of b"}
    ]
    }
}

This is useful in finding errors in your Track. If we now alter the Track so that it tries to reference the missing variable "X", you wil be able to see where the error occurs:

{
    "js" : "function (input_drop) {
       var a = input_drop.elems.a.value;
       console.log('before setting the value of b');
       input_drop.elems.b = X  * 3;   // <- missing variable !!
       return input_drop;
     }"
  }
}

returns

 "body" : {
    "drops" : [
      { "elems" : { "a" : 1, "b" : 3.0 } }
    ],
    "log" : [
      { "line_no" : 2 },
      { "console" : "before setting the value of b" }
    ],
    "errors" : [ "ReferenceError: \"X\" is not defined" ]
  }