Using a Task to Periodically Send Data to External Systems

You can use a Task to periodically send data to external systems. By using a Task you define JavaScript code that uses the Cloud Action API to access Events in Streams and define the periodicity at which to execute that code.

Follow the steps below to create a Task that periodically finds Events in a Stream and sends them to an external cloud system:

  1. Create a Task.
  2. Within the Task's JavaScript function invoke Octave's Octave.Event.find() cloud API to find 10 Events from the Stream whose ID starts with s5b7 and sorts them by creation date. Then package those Events into a JSON payload and use Octave's Octave.Http.post() API to POST that data to an external cloud service:
function() {

  // Octave.Event.find(streamId, options)
  var events = Octave.Event.find("s5b7...", {"sort":"creationDate", "limit": 10});

  var body = JSON.stringify({ "event_received": events });
  var urlAPI = 'http://myprivateapi.com/endpoint'
  var options = {
            'Content-Type': 'application/json'
        };
  var resultPost = Octave.Http.post(urlAPI, options, body);

}