Hi Everyone,
I’m working on a project where I’ve written a javascript XMLHttpsRequest following this guide: https://api.qualtrics.com/af95194dd116e-list-contacts-in-mailing-list to retrieve contacts from a mailing list, search for a specific ExtRef value (krid below), and grab the needed information and save it as embedded variables. The code below is working:
Qualtrics.SurveyEngine.addOnload(function()
{
const data = null;
const xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
const obj = this.responseText;
var krid = "${e://Field/krid}";
var string = JSON.stringify(obj);
var extract1 = string.split(krid)i0];
var extract2 = extract1.split("contactId").pop();
var split = extract2.split('"');
var f_name = split 6];
f_name = f_name.substring(0, f_name.length -1);
var l_name = split 10];
l_name = l_name.substring(0, l_name.length -1);
var email = split 14];
email = email.substring(0, email.length -1);
var phone = split 18];
phone = phone.substring(0, phone.length -1);
console.log(f_name);
console.log(l_name);
console.log(email);
console.log(phone);
Qualtrics.SurveyEngine.setEmbeddedData("f_name", f_name);
Qualtrics.SurveyEngine.setEmbeddedData("l_name", l_name);
Qualtrics.SurveyEngine.setEmbeddedData("email_address", email);
Qualtrics.SurveyEngine.setEmbeddedData("phone", phone);
}
});
xhr.open("GET", "https://xxx1.qualtrics.com/API/v3/directories/XXX/mailinglists/XXX/contacts");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("X-API-TOKEN", "XXX");
xhr.send(data);
});
While this works when there are fewer than 50 contacts on the list, it starts to pull the last contact on the list if the ExtRef searched for does not exist in the first 50 shown. I understand that the nextPage value included in the result, if not null, includes the skipToken value which can be used as the appropriate offset to grab the next set of 50 contacts, and while I have done this manually, I am struggling to loop through all the available pages and join all of the results before searching.
I’d really appreciate any help here.