HTTP Callout Policy
The callout-http policy invokes an HTTP(S) URL and places a subset or all of the content in one or more variables of the request execution context.
This can be useful if you need some data from an external service and want to inject it during request processing.
This policy can be attached to the following phases:
-
onRequest/onRequestContent: Executed before the request reaches your backend service. -
onResponse/onResponseContent: Executed after the backend service responds, but before the client receives it.
By default, the callout result is stored in a temporary calloutResponse variable available only while the policy is executing. To use this data in subsequent policies or send it to your backend, you must define a custom variable in the variables configuration property.
Timing
| On Request | On Response |
|---|---|
| X | X |
Configuration
| Property | Required | Description | Type | Default |
|---|---|---|---|---|
method | yes | HTTP Method used to invoke URL. Options are: CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, TRACE | HTTP method | GET |
url | yes | URL invoked by the HTTP client (supports EL). | URL | |
Cache Enabled | no | Enables or disables caching for this policy. Set to true to enable the caching mechanism. | Boolean | false |
Cache Refresh Time | no | Specifies the cache duration in seconds. Use this to set a static Time-to-Live (TTL) for cached data. The default value is 3600 seconds (1hour). | Integer | 3600 |
Cache Key | yes | Defines the unique identifier for a cached entry. Construct the key using specific request attributes—such as path, query parameters, or headers—to ensure that each request has a unique cache entry. Warning: When updating existing or configuring new HTTP Callout policies with caching disabled, you must still populate the Cache Key field with a placeholder string (e.g., not-applicable or temp) to satisfy the mandatory field requirement. Please note that this is a temporary requirement and will be resolved in the upcoming release. | String | "" |
headers | no | List of HTTP headers used to invoke the URL (supports EL). | HTTP headers | |
body | no | The body content send when calling the URL (supports EL). | string | |
fireAndForget | no | Make the HTTP call without expecting any response. When activating this mode, context variables and exit on error are ignored. | boolean | false |
variables | no | The variables to set in the execution context when retrieving content of HTTP call (supports EL). Use the variables to persist data for use in later policies. | List of variables | |
exitOnError | no | Terminate the request if the error condition is true. | boolean | false |
errorCondition | no | The condition that will be verified to end the request (supports EL). | string | {#calloutResponse.status >= 400 and #calloutResponse.status <= 599} |
errorStatusCode | no | HTTP Status Code sent to the consumer if the condition is true. | int | 500 |
errorContent | no | The body response of the error if the condition is true (supports EL). | string |
Example
In this example, a value is extracted from the calloutResponse and stored in a variable named my-server. You can then reference this in a later policy (such as Transform Headers) using the syntax {#context.attributes['my-server']}.
{
"policy-http-callout": {
"method": "GET",
"url": "https://api.boomi.io/echo",
"cacheEnabled": false,
"cacheRefreshTime": 3600,
"cacheKey": "",
"headers": [
{
"name": "Authorization",
"value": "{#request.headers['Authorization']}"
}
],
"body": "{}",
"fireAndForget": false,
"variables": [
{
"name": "my-server",
"value": "{#jsonPath(#calloutResponse.content, '$.msg')}"
}
],
"exitOnError": false,
"errorCondition": "{#calloutResponse.status>= 400 and #calloutResponse.status<= 599}",
"errorStatusCode": 400,
"errorContent": "Getting error while invoking the url",
"scope": "REQUEST"
}
}
Override errors
You can override the default response provided by the policy with the response templates feature. These templates must be defined at the API level with the APIM Console Proxy > Response Templates function. Use the following keys to override the default behavior:
-
CALLOUT_EXIT_ON_ERROR: Message sent when the errorCondition is met.
-
CALLOUT_HTTP_ERROR: Message sent when the Gateway fails to connect to the destination URL.