POSTing Data via Webhooks

You can use the Octave.Http.* methods such as HTTP POST within your Cloud Actions, to send and receive data via webhooks exposed by external cloud services. These methods allow you to include all of the standard elements of a REST request such as headers, body parameters, etc. and to receive responses.

For example, the following code creates a REST request and places a stringified version of the event into the request body. The body, along with a header, are then sent to a webhook via a POST request, and the result from the request is returned:

function(event) {

   ...

    var url = 'http://httpbin.org/post';
    var postBody = JSON.stringify(event);
    var postHeaders = {
    'Content-Type': 'application/json',
    'header2': '2'
    };
    var result = Octave.Http.post(url, postHeaders, postBody);

    return {
    "js": "function(event) { return {\\"/my_company/destination\\": [event]} }"
    }
}

It's important to check the result to identify the status code in order to determine what logic to perform next in your Cloud Action. For example, if status code 201 - Created is returned, then the operation was successful and any resources requested can be found in other fields of the result. On the other hand, if status code 202 - Accepted is returned, then a subsequent request to the webhook may be required in order to check the status of any remote processes. In this case you check the status by invoking another REST request in a different event.