> For the complete documentation index, see [llms.txt](https://docs.sharelogic.com/unifi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sharelogic.com/unifi/configure/polling/poll-processors.md).

# Poll Processors

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)*.&#x20;

{% hint style="info" %}
If you want to stop poller execution in the setup script without throwing an error you can set: `ignore=true;` .
{% endhint %}

## 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](#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`).

```javascript
// ... 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.&#x20;

<pre class="language-javascript"><code class="lang-javascript">if (connection.useBasicAuth()) {
	console.debug('Using basic authentication');
	request.setBasicAuth(connection.getBasicAuthUser(), connection.getBasicAuthPassword());
}
else if (connection.useOAuth()) {
	console.debug('Using OAuth');
<strong>	request.setRequestorProfile('x_snd_eb_connection', connection.getValue('sys_id'));
</strong>	request.setAuthenticationProfile('oauth2', connection.getOAuthProfile());
}
// MutualAuth is less common so generally not needed.
else if (connection.useMutualAuth()) {
	console.debug('Using mutual authentication');
	request.setMutualAuth(connection.getProtocolProfileName()); // [String] profileName
}
</code></pre>

{% hint style="warning" %}
If you are having issues with OAuth, check our [How to Setup an OAuth Connection](/unifi/configure/how-to-guides/how-to-setup-an-oauth-connection.md) 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.
{% endhint %}
