HTTP Poll
HTTP Poll task is used to invoke HTTP API endpoints until the specified condition matches.
Definitions
{
"name": "http_poll",
"taskReferenceName": "http_poll_ref",
"type": "HTTP_POLL",
"inputParameters": {
"http_request": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"terminationCondition": "(function(){ return $.output.response.body.randomInt > 10;})();",
"pollingInterval": "60",
"pollingStrategy": "FIXED",
"encode": true,
"headers": {
"Cache-Control": "${workflow.input.cache.control}"
},
"body": {
"key": "value"
}
}
},
"cacheConfig": {
"ttlInSecond": 2000,
"key": "cache-key"
},
"optional": false
}
Input Parameters
Attribute | Description |
---|---|
uri | Provide the URI for the service. It can be a partial value when using vipAddress or it can be the server address. |
method | Choose the HTTP method. Conductor supports the methods: GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, and TRACE. |
accept | Provide the accept header as required by the server. The supported types are:
|
contentType | Provide the content type for the server. The supported types are:
|
terminationCondition | Specifies the condition to be evaluated after every HTTP API invocation. If the condition is evaluated as true, the task will be marked as completed. On the other hand, if the condition is evaluated as false, Conductor will schedule the next poll according to the configurations (pollingInterval & pollingStrategy). While writing the termination condition,
(function(){ return $.output.response.body.randomInt > 10;})(); |
pollingInterval | Specify the time duration in seconds between each HTTP invocation. By default, the value is set to 60. |
pollingStrategy | Choose the required polling strategy. It can take any of the following values:
|
headers | A map of additional HTTP headers to be sent along with the request. The supported types are:
|
body | Request body when using POST, PUT, or PATCH. It can be added as text ("body": "text") or parameters such as string, number, boolean, null, or object/array. |
encode | Determines whether the URI needs encoding. When set to true (the default), the Conductor will automatically encode the query parameters before sending the HTTP request. Set this to false if the URI is already encoded. In this case, the Conductor will assume the query parameters are properly encoded and pass them to the HTTP endpoint as specified in the URI. |
cacheConfig | Enabling this option allows saving the cache output of the task. On enabling, you can provide the following parameters:
|
optional | Enabling this option renders the task optional. The workflow continues unaffected by the task's outcome, whether it fails or remains incomplete. |
Output Parameters
Attribute | Description |
---|---|
response | A JSON object representing the response, if present. |
headers | An object containing the metadata about the response. |
statusCode | Returns the HTTP status code indicating the success or failure of the request. |
reasonPhrase | Returns the reason phrase associated with the HTTP status code. |
body | Returns the body of the response containing the actual data returned by the API. |
Examples
- UI
- JSON
- Add task type HTTP Poll.
- Configure polling endpoint, interval, strategy, and termination condition.
{
"name": "http_poll",
"taskReferenceName": "http_poll_ref",
"type": "HTTP_POLL",
"inputParameters": {
"http_request": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"terminationCondition": "(function(){ return $.output.response.body.randomInt > 10;})();",
"pollingInterval": "60",
"pollingStrategy": "FIXED",
"encode": true,
"headers": {
"Cache-Control": "${workflow.input.cache.control}"
},
"body": {
"key": "value"
}
}
},
"cacheConfig": {
"ttlInSecond": 2000,
"key": "cache-key"
},
"optional": false
}
Sample Workflow
Let’s see a sample workflow:
{
"name": "your_workflow_name",
"description": "Sample workflow to get started with HTTP POLL task.",
"tasks": [
{
"name": "example",
"taskReferenceName": "example",
"inputParameters": {
"http_request": {
"uri": "https://jsonplaceholder.typicode.com/posts/1",
"method": "GET",
"terminationCondition": "$.output.body.length > 10 ? true : false;",
"pollingInterval": "60",
"pollingStrategy": "FIXED"
}
},
"type": "HTTP_POLL"
}
]
}
So, here, the input parameters for the HTTP Poll task are defined as follows:
"terminationCondition": "$.output.body.length > 10 ? true : false;",
"pollingInterval": "60",
"pollingStrategy": "FIXED"
Conductor will invoke the HTTP API every 60 seconds until the invoked URI gives the output that is longer than 10 characters.