Invoke a REST/HTTP API to an external system. This can be used to interact with other systems that are not accessible via browsers, such as a PSTN telephony infrastructure or an external Database.
Arguments
Name | Type | Description |
---|---|---|
url | string / object |
External REST/HTTP server API URL. It is also possible to use an object to set HTTP headers to the request (see additional details below). |
input (optional) | object | If exists – send as HTTP POST with the
input object converted to JSON as body of the
request. If does not exist – send as HTTP GET request. |
answer | string | The external REST server response. |
Code example
//This will send HTTP POST to the to save some data
.rtcActivateWebhook(restURL, { value: sampleValue }, function(answer) {
client.rtcInfo('rtcActivateWebhook Post answer ' + answer);
})
//This will send HTTP Get to the same url to retrive the just posted data
.rtcActivateWebhook(restURL, function(answer) {
client.rtcInfo('rtcActivateWebhook Get answer' + answer);
})
HTTP Headers
It is possible to set the Webhook HTTP header, by using the url argument as a
json object and adding the header fields as the object’s internal json
object. For
example:
var webHookOptions = {
url: 'https://[url]',
headers: {
'X-HTTP-Method-Override': 'PATCH',
'Cache-Control': 'no-cache',
'Content-Type': 'text/xml'
}
};
client.rtcActivateWebhook(webHookOptions, {value: 100}, function(answer) {
. . .
})
Note: A complete sample test script source, that uses the
rtcActivateWebhook() command, can be found here.