Issuing REST Requests from Within Cloud Actions

A Cloud Action consists of JavaScript that is invoked by Octave when an event occurs, and writes a value to a specific stream. For example, the code shown in Setting a Value From a Cloud Action demonstrates how an update to a weather reading can be written to a stream.

Within a Cloud Action you also have the option to invoke REST requests using Octave's http methods such as Octave.Http.get(), and to set up Webhooks to bring in data from an external system.

For additional APIs see: Cloud JavaScript Library.

The steps below example illustrate how to set up a Cloud Action to invoke a REST GET request:

  1. Navigate to Device > Cloud > Actions.
  2. Click New Cloud Action.
  3. Set Source type to Stream.
  4. Click on Stream and select the stream from which to process events.
  5. Click on Action name and enter a meaningful name to identify the Cloud Action.
  6. Set Input to Get HTTP response. This template illustrates how to send an HTTP request to an external API.
function(event) {
   var options = { "X_API_KEY": "AN API KEY", "OTHER_HEADER": "OTHER HEADER VALUE" };
   // With a GET method
   var resultGet = Octave.Http.get("http://myprivateapi.com/endpoint", options);

   // Your code here

   return {}
}
  1. Click Continue.
  2. Modify the code as required for your cloud action.
  3. Click Create Cloud Action to create the Cloud Action.