PureText Buyer API Integration in Qualtrics
OVERVIEW
This API checks for the Open-Ended (OE) survey responses to ensure data quality. It performs language comparison, AI-generated answer detection, exclusion list checks, and PureText deduplication. Below is the processing flow:
- Language Compare: Compares the language of the OE answer with the survey language determined from the transaction ID
- AI Detection: Detects whether the answer is AI-generated
- Exclusion List: Checks if the answer is in an exclusion list of undesirable responses
- PureText Deduplication: Ensures the answer's uniqueness through deduplication
Pre-Requisites
- Need to add below host names in the decipher directory.
- For Production: https://spectrumsurveys.com/
- For Staging: https://staging.spectrumsurveys.com/
- API Access token
- Valid transaction_id
-
question_id: string or number or alpha numeric.
- Examples are Q1, S1 etc.
- text: Survey Response to validate.
-
Endpoint
- POST /buyers/v3/transactions/ps_api_fail
How to get API access token from Market Place
If you are an API user, you already have a API access token or one could be created for you. Please contact your Account manager to know how to get the access token for your account.
How to Program in Qualtrics
Login into Qualtrics platform and open/create your project and follow the steps outlined below.
Step 1: Create transaction_id as embedded variables
- Click on Survey Flow
- Click on Add a New Element, click on Embedded Data
- Add “transaction_id” as an Embedded Data element
- Move this element to the top of the Survey Flow
Step 2: Create a group after the block, which contains open end questions to add API request for validation and to add termination.
- Click on Add a New Element, click on Group and name it
- Click on Add a New Element within the group, click on Web Service and name it.
- Please fill API URL, Method, Query/Body parameters, custom header(access-
token) and set embedded data with results. See Details below.
Details (API URL, Method, Query/Body parameters, custom header, embedded data)
URL:
- Copy and paste
https://spectrumsurveys.com/buyers/v3/transactions/ps_api_fail
Method
- Select POST
Body Parameter:
- Click on Add a body parameter to send to web service.
- Select application/json from drop down.
- Add transaction_id and select the String as data type from drop-down and set transaction_id received from panel as value.
- Add questions and select the JSON as data type from drop-down and then build the JSON with all the question ids and pipe related open end as an e.g. below.
[
{
"question_id": "Q1",
"text": "${q://QID179/QuestionText}"
},
{
"question_id": "Q2_other",
"text": "${q://QID183/ChoiceTextEntryValue/4}"
}
]
Custom Header:
- Add access-token and set API access token from Market Place
Set Embedded Data:
- Add embedded variables and set transaction_id, ps_buy_api_status_code, ps_api_response_message as values and name them accordingly.
- Add a few more embedded variables and set data.0.puretext_api_fail, data.0.ai_generated_response, data.0.incoherent_response, data.0.duplicate_response, data.0.language_mismatch, data.0.original_transaction_id, data.0.question_id for Q1 results and name them accordingly. In this example, we named Q1.puretext_api_fail, Q1.ai_generated_response, Q1.incoherent_response, Q1.duplicate_response, Q1.language_mismatch, Q1.original_transaction_id, Q1.question_id for clear and easy reference.
- Add a few more embedded variables and set data.1.puretext_api_fail, data.1.ai_generated_response, data.1.incoherent_response, data.1.duplicate_response, data.1.language_mismatch, data.1.original_transaction_id, data.1.question_id for Q2_other results and name them accordingly.
- If you have more questions, please continue adding embedded variables with data.2.xxx, data.3.xxx etc.
We have taken two questions to build this example (i.e. Q1 and Q2).
Example
Step 3: Create 11 embedded variables with the below names to capture the consolidated results. (Click on Add a New Element, click on Embedded Data.)
1. PT_puretext_api_fail_Result_Set1: Indicates the count of all the flags where the respondents failed. For example, if the respondent was flagged due to incoherent response at Q1 and language mismatch at Q2. Then this count will be 2 (consolidated count).
2. PT_puretext_api_fail_QIDs_Set1: Indicates the question ids (with comma separation) which the respondents failed. For example, if the respondent was flagged due to incoherent response at Q1 and language mismatch at Q2. Then it shows “ Q1, Q2”
3. PT_ai_generated_response_COUNT_Set1: Indicates the count of all questions where the respondent failed due to AI generated text.
4. PT_ai_generated_response_QIDs_Set1: Shows the list of all question ids with the comma separation where the respondent failed due to AI generated text.
5. PT_incoherent_response_COUNT_Set1: Indicates the count of all questions where the questions failed due to incoherent/junk response.
6. PT_incoherent_response_QIDs_Set1: Shows the list of all question ids with the comma separation where the questions are failed due to incoherent/junk response.
7. PT_duplicate_response_COUNT_Set1: Indicates the count of all questions where the questions failed due to duplicate response.
8. PT_duplicate_response_QIDs_Set1: Shows the list of all question ids with the comma separation where the questions failed due to duplicate response.
9. PT_language_mismatch_COUNT_Set1: Indicates the count of all questions where the questions are failed due to language mismatch.
10. PT_language_mismatch_QIDs_Set1: Shows the list of all question ids with the comma separation where the questions are failed due to language mismatch.
11. PT_original_transaction_dedupe_id: Only in case of PT Deduplicate fail, this shows the list of all question ids and the original transaction_id that was duplicated from.
Step 4: Then, please add a Text/Graphic screen before the embedded variables created in step 3. We will add java script in this node to set the values for embedded variables, add below style tag in question text along with “Please wait...” text.
<style type="text/css">#NextButton,#Questions {
display: none;
}
</style>
And then please copy the script below into the Java script area which will be opened if you click on above green highlighted area.
JavaScript
Qualtrics.SurveyEngine.addOnload(function()
{
});
Qualtrics.SurveyEngine.addOnReady(function()
{
var arrQ1 =
["${e://Field/Q1.puretext_api_fail}","${e://Field/Q1.ai_generated_response}","${e://Field/Q1.incoherent_response}","${e://Field/Q1
.duplicate_response}","${e://Field/Q1.language_mismatch}","${e://Field/Q1.original_transaction_id}","${e://Field/Q1.question_id}"]
var arrQ2 =
["${e://Field/Q2.puretext_api_fail}","${e://Field/Q2.ai_generated_response}","${e://Field/Q2.incoherent_response}","${e://Field/Q2
.duplicate_response}","${e://Field/Q2.language_mismatch}","${e://Field/Q2.original_transaction_id}","${e://Field/Q2.question_id}"]
var arrQ3_1 =
["${e://Field/Q3_1.puretext_api_fail}","${e://Field/Q3_1.ai_generated_response}","${e://Field/Q3_1.incoherent_response}","${e://Fi
eld/Q3_1.duplicate_response}","${e://Field/Q3_1.language_mismatch}","${e://Field/Q3_1.original_transaction_id}","${e://Field/Q3_
1.question_id}"]
var Farray = [arrQ1, arrQ2, arrQ3_1];
var api=0, agr = 0, ir = 0, dr = 0, lm=0;
var apiA = []
var agrA = [];
var irA = [];
var drA = [];
var lmA = [];
var otA = [];
for(var i=0;i<Farray.length;i++)
{
var qid= Farray[i][6]
var ot_qid= Farray[i][5]
if(Farray[i][1] > 0)
{
agr = agr+1
agrA.push(qid)
}
if(Farray[i][2] > 0)
{
ir = ir+1
irA.push(qid)
}
if(Farray[i][3] > 0)
{
dr = dr+1
drA.push(qid)
}
if(Farray[i][4] > 0)
{
lm = lm+1
lmA.push(qid)
}
if(ot_qid.length > 0)
{
var qotid = qid+":"+ot_qid
otA.push(qotid)
}
api = agr+ir+dr+lm
apiA = [...new Set([...agrA, ...irA, ...drA, ...lmA])];
console.log(api+"xxx"+apiA+"xxx"+otA)
Qualtrics.SurveyEngine.setEmbeddedData('PT_puretext_api_fail_Result_Set1',api);
Qualtrics.SurveyEngine.setEmbeddedData('PT_puretext_api_fail_QIDs_Set1',apiA);
Qualtrics.SurveyEngine.setEmbeddedData('PT_ai_generated_response_COUNT_Set1',agr);
Qualtrics.SurveyEngine.setEmbeddedData('PT_ai_generated_response_QIDs_Set1',agrA);
Qualtrics.SurveyEngine.setEmbeddedData('PT_incoherent_response_COUNT_Set1',ir);
Qualtrics.SurveyEngine.setEmbeddedData('PT_incoherent_response_QIDs_Set1',irA);
Qualtrics.SurveyEngine.setEmbeddedData('PT_duplicate_response_COUNT_Set1',dr);
Qualtrics.SurveyEngine.setEmbeddedData('PT_duplicate_response_QIDs_Set1',drA);
Qualtrics.SurveyEngine.setEmbeddedData('PT_language_mismatch_COUNT_Set1',lm);
Qualtrics.SurveyEngine.setEmbeddedData('PT_language_mismatch_QIDs_Set1',lmA);
Qualtrics.SurveyEngine.setEmbeddedData('PT_original_transaction_dedupe_id',otA);
setTimeout(function() {
jQuery("#NextButton").click()
}, 1000);
});
Qualtrics.SurveyEngine.addOnUnload(function()
{
});
Step 5: Then, please update the yellow highlighted arrays with the embedded variables created to store the Puretext API results in Step 2 as shown in the code.
Step 6: Termination Process, create branch and add the below condition for termination.
- Click on Add a New Element, click on branch and add condition on embedded variables created based on PT_puretext_api_fail_Result_Set1.
- Greater than or equal to 1 is Failed
- 0 is Successful
- To terminate the session, add the End of Survey element within this branch. At this point the respondent session can be terminated (if >= 1) or let to continue (if==0) based on the API call response.
- Click on the option Customize and reference the below screenshot to set the fields as below.
Step 7: Important - Click on Apply to save changes.
Possible Errors