HTTP Poll
The HTTP Poll task is used to invoke HTTP API endpoints until the specified condition matches.
An HTTP Poll task sends HTTP requests to a specified endpoint at regular intervals and continues until a given termination condition is met. This is useful when you need to repeatedly check an HTTP service's status or output.
Task parameters
Configure these parameters for the HTTP Poll task.
Parameter | Description | Required/Optional |
---|---|---|
inputParameters.uri | The URI for the service. It can be a partial value when using vipAddress or it can be the server address. | Required. |
inputParameters.method | The HTTP method. Supported methods:
| Required. |
inputParameters.accept | The accept header required by the server. The default value is application/json . Supported types:
| Optional. |
inputParameters.contentType | The content type for the server. The default value is application/json . Supported types:
| Optional. |
inputParameters.terminationCondition | The condition to be evaluated after every HTTP API invocation. If the condition is evaluated as true , the task is marked as completed. If the condition evaluates to false , Conductor schedules the next poll according to the configurations (_pollingInterval_ and _pollingStrategy_ ).When writing the termination condition, it can be passed as variables. To use the current HTTP poll as input to the condition, prefix it with a $ . For example, $.output.status . Similarly, refer to previous tasks' output using $.task_ref_name.output .Example Termination Condition- (function(){ return $.output.response.body.randomInt > 10;})(); | Required. |
inputParameters.pollingInterval | The duration in seconds between each HTTP invocation. The default value is 60. | Required. |
inputParameters.pollingStrategy | The polling strategy. Supported values:
| Required. |
inputParameters.headers | A map of additional HTTP headers to be sent along with the request. Supported types:
| Optional. |
inputParameters.body | The request body for POST, PUT, or PATCH methods. Can be text or parameters such as string, number, boolean, null, or object/array. | Required for POST, PUT, or PATCH. |
inputParameters.encode | Determines whether the URI needs encoding. When set to true , the Conductor will automatically encode the query parameters before sending the HTTP request. Set this to false if the URI is already encoded. The default value is true. | Optional. |
Task configuration
This is the task configuration for an HTTP Poll task.
{
"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": {
"header-1": "${workflow.input.header-1}"
},
"body": {
"key": "value"
}
}
}
}
Task output
The HTTP Poll task will return the following parameters.
Parameter | Description |
---|---|
response | A JSON object representing the response, if present. |
headers | An object containing the metadata about the response. |
statusCode | The HTTP status code indicating success or failure of the request. |
reasonPhrase | The reason phrase associated with the HTTP status code. |
body | The response body containing the data returned by the API. |
Adding an HTTP Poll task in UI
To add an HTTP Poll task:
- In your workflow, select the (+) icon and add an HTTP Poll task.
- Choose the HTTP method for sending requests from the Method drop-down.
- In URL, add the URI to be called by the HTTP Poll task.
- In Accept, select the accept header as required by the server.
- In Content-Type, select the content type for the server.
- In Termination Condition, set the condition to be evaluated after every API invocation.
- Set the Polling Interval and Polling Strategy.
- (Optional) In Other-headers, add any additional HTTP headers to be sent along with the request.
- In Body, add the request body when using PUT, POST, or PATCH method.
- (Optional) Enable or disable Encode to specify if the URI needs to be encoded.
Examples
Here are some examples for using the HTTP Poll task.
Sample Workflow
To demonstrate the HTTP Poll task, consider the following 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"
}
]
}
In this configuration, the polling conditions are configured as follows:
- uri - Specifies the endpoint to be called (https://jsonplaceholder.typicode.com/posts/1 in this example).
- method - Defines the HTTP method used for the request (GET in this case).
- terminationCondition - Evaluate whether the length of the response body ($.output.body.length) exceeds ten characters to determine task completion.
- pollingInterval - Sets the interval (60 seconds) between successive API invocations.
- pollingStrategy - Utilizes a FIXED strategy to maintain a constant interval between invocations.
Conductor will execute the HTTP API call every 60 seconds until the condition (response body length > 10) evaluates to true.