As with the Internal API Call interceptor, Service Callout allows an API to invoke a call based on pre-defined settings. The difference is that, while the former redirects a call to APIs that are available in the Sensedia Platform, Service Callout allows invoking an external call.
The images and text below present the information that must be informed to configure the interceptor.



$call.contextVariables using the name informed here.
A custom interceptor is required for this, as shown below.WARNINGThe Transfer-Encoding header is removed when the request travels through the gateway, both in response and in request. For more information on removing headers, click here.

Service Callout has the ability to make synchronous or asynchronous calls. In the former case, a synchronous call will be sent to the new URL and the interceptor will await the result to continue the execution of the flow. For asynchronous calls, select the field Asynchronous.
NOTEThe interceptor Service Mashup must be inserted in the API flow to allow capturing the response of asynchronous calls.
You can select the option Fire and Forget or leave it unchecked. If you select it, the interceptor will send the request and forget it, meaning that there will be no return from the external call.
When the option is not selected, you can configure a time limit for the external call to be made. The call will be terminated if the timeout reaches its limit or a result is returned.

The status codes returned by Service Callout when an error occurs, and the reasons for them, are:
To show how Service Callout works, let's consider the following case:
NOTEAn organization, the LSA (Lost Souls' Alliance), will develop a central API, LSA Communication, which will be able to send, via POST, the same message (or command) to people inside and outside the organization. This API will be registered under the domain lsa.org.mx.
The message, sent as a JSON in the body of the call, will be:
In the case of external communication, there is an API exposed, under the domain lsa-spies.org.mx and external to the Sensedia platform, which allows sending the message through the external system (pigeons). This system has two resources for this: pigeons/pigeon-manny and pigeons/pigeon-meche. To take advantage of this API, we use Service Callout.
Since they are different resources, two Service Callout interceptors will be used. The following images show, respectively, the sequence of the interceptors in the API flow and the settings used in the interceptor that makes the POST call to pigeons/pigeon-manny, the settings for pigeons/pigeon-meche being similar:


It is important to point out that, because they have been configured to work synchronously, the second Service Callout interceptor will only be executed after the first one has finished executing. When execution time is a relevant issue, it is recommended to use asynchronous calls, as exemplified in the use of Service Mashup.
The call to pigeons/pigeon-manny returns, with status code 200, the following body:
On the other hand, the call to pigeons/pigeon-meche returns, also with status code 200, the following body:
After each synchronous call, the interceptor will return an object of type RESTResponse that will be stored in the call's context variables.
To retrieve the response, you need to create a custom interceptor that accesses $call.contextVariables.get("Variable Name").
Below is the code for the custom JavaScript interceptor that will be used to capture the responses and include the bodies and status in the final response:
Finally, the body of the response of the POST call to the external-messages resource of LSA Communication will be:
We use cookies to enhance your experience on our site. By continuing to browse, you agree to our use of cookies.Learn more