Poll Processors
Poll Processors are used to setup, execute and process Poll Requests.
The Poll Processor is a configuration record which contains the logic that will be applied when polling a remote system for data. There are three main scripts which are used to setup, execute and process the Poll Requests.
Setup Script
The Setup Script is the first script to run (it runs at the point in time the Poll Request is created). It is used to build the environment for the poll and define what it will do (for example, create/setup the URL that will be called). It also supplies a params object as one of the arguments, which will be passed through to the subsequent scripts (and on to further Pollers, if required).
Request Script
The Request Script is used to reach into the remote system and execute the request. This is usually done by making a REST call to the URL defined in the Setup Script. The request response may then be written to the Poll Request with automatic request script logging.
Response Script
The Response Script is used to process the information returned from the remote system. This could include converting the data from its proprietary format to a more usable format, sending the data to Unifi, or even kicking off a new poll.
Script Examples
Request Script Logging
The following shows an extract of a Request Script that executes a REST message and writes the response details to the Poll Request record(x_snd_eb_poll_request).
// ... RESTMessageV2 creation and population.
var resp = rm.execute(); // rm is a RESTMessageV2 object
// Set Status code on response object
poll_request.response_code = resp.getStatusCode();
// Set the answer object to pass the response body to the Response script
// This also populates response_size
answer = resp.getBody() + '';
if (resp.haveError()) {
// Set response status to contain error
poll_request.response_status = resp.getErrorMessage();
// Throw the error to error the poller
throw '\nResponse Code: ' + resp.getStatusCode() + ' \nResponse error: ' +
resp.getErrorMessage();
}Request Authentication
The following is an extract of a Request Script that allows the request to authenticate regardless of the authentication type selected on the connection.
If you are having issues with OAuth, check our How to Setup an OAuth Connection guide and make sure the tokens are refreshed. Also ensure the connection user can access your OAuth tokens by navigating to System Oauth > Manage Tokens and set the 'User' to the connection user.
Last updated
Was this helpful?
