CurlPoll

Description

Use this function to make a REST API request continuously until a regular expression is matched or timeout is reached. You'll find it useful with asynchronous API calls that require polling for a status / response URL.

Syntax

CurlPoll(regex_string,interval, timeout, url, method[, headers[, request_body[, username[, password]]]])

Arguments

regex_string - regular expression string to match the response. If the regular expression is matched, the response is returned by the function.

interval - Interval in milliseconds to wait between requests.

timeout - Function will timeout after specified timeout (in milliseconds), stop making the requests and return the last response.

url - HTTP or HTTPS url for the request.

method - HTTP method, such as GET, POST, PUT, DELETE.

headers (optional) - A json string that identifies the header key and value in the following manner: '{"header1" : "value1" , "header2" : "value2"}'

request_body (optional) - The string body of the request (most relevant in the case of POST)

username (optional) - The user name for basic authentication. Can be empty string if the site does not require authentication.

password (optional) - The password for basic authentication. Can be empty string if the site does not require authentication.

Examples

CurlPoll('status="(completed|failed)',1000,60000, 'http://api.myapp.com/report/1234/status','GET','{"Accept":"text/json"}','','','')

Return value datatype

The returned value is a map object that contains the following keys:

  • status - response code (integer)
  • body - the body of the response (string)
  • headers - map object of response headers

Impact of null value

The regex_string, interval, timeout, url and method arguments are required. The rest are optional and default to null.