This guide will walk you through the process of verifying user input using PureSpectrum's [PureText buyer API](https://purespectrum.atlassian.net/wiki/spaces/PBA/pages/2771222529/PureText+Buyer+API+V3) within your survey.
To validate a user input, an API call has to be made to PureSpectrum, which will respond with a JSON object that looks like this:
```json
{
"transaction_id": "2W6ZHlCrBZIgyf9kH04Stb",
"buyer_ps_api_fail": true
}
```
The transaction_id is specific to each respondent and should be provided as a [Link Variable](https://sawtoothsoftware.com/help/lighthouse-studio/manual/ids-and-variables.html?q=pass+in+variable), which should be provided by PureSpectrum when the respondent is being redirected to your Sawtooth survey.
To make the API call easier, we have implemented a Sawtooth Script function for you. The usage of this function is described in the next section.
In your Open-end question, click on the "Skip Logic" tab. Then, click "Add" to add a new skip logic to the "Question Skips" table. In the "Skip Settings", click "Skip if the following logic evaluates to true". Implement the skip logic in the text box as follows:
```
[% PureTextBuyerAPI("question_id", "text to be evaluated", "transaction_id", "access_token") %]
```
The question_id should be identifiable by you so it can be the question name, which can be retrieved by using the Sawtooth Script, [`QUESTIONNAME()`](https://sawtoothsoftware.com/help/lighthouse-studio/manual/system-functions.html). The text to be evaluated can be obtained by calling the `GETVALUE(QUESTIONNAME())` function. If your link variable containing the transaction_id is "ID", then you can retrieve the ID by calling `GETVALUE(ID)`. Your access token should be secret to you and should be used with care. In here, you can safely place your token in the function as the skip logic will be evaluated in the server.
You may be wondering why all the Sawtooth Scripts are in uppercase. This is because you are using them in a Perl context and their function names are all in uppercase.
Currently, PureSpectrum expects a redirect once a survey is complete or terminated. The redirect URLs have this form:
- https://spectrumsurveys.com/surveydone?st=[status]&transaction_id=[transaction_id]
For more information about what each status code corresponds to, see the [PureSpectrum documentation](https://purespectrum.helpjuice.com/en_US/create-and-launch-a-survey/finalize-and-launch).
In the following example, we will be using the status 21, which means the survey is successfully completed.
To implement the redirect, create a terminate question type. In the "Settings" tab, select the "Redirect Behavior" to anything other than "Do not redirect". In the "Web Address" text box, add the corresponding redirect URL, which is
- https://spectrumsurveys.com/surveydone?st=21&transaction_id=[% GetValue(ID) %]
in this example. Note that Sawtooth Script, GetValue(ID), is used to retrieve the transaction id from the database. For more details about Sawtooth Script, see the [System Functions](https://sawtoothsoftware.com/help/lighthouse-studio/manual/system-functions.html) section.