Workflow API call in loop | XM Community
Skip to main content

I am working with Qualtrics workflow in which pulling survey response to Podio using API.

In one scenario, I wanted loop for API call which is based on answer to question.

In workflow itself, there is no option for looping.

I have tried with custom code, with help of JavaScript fetch/XMLHttpRequest function. I was trying to call API in loop. While testing on code itself it is working (attached screenshot), but when actual workflow hit, it is giving error like - fetch/XMLHttpRequest is not defined.

 

Please find my script below -

    var resData =  ];
if("~{ch://OCAC_2ffYcEDG3eY39Ut/statusCode}" == 200){

var projectNumbers = "${q://QID3/ChoiceGroup/SelectedChoicesTextEntry}".split(", ");
projectNumbers.forEach(function (number, index) {

var xhttp = new XMLHttpRequest();
xhttp.open("POST", "https://api.podio.com/item/app/16099995/filter", true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.setRequestHeader("Accept", "application/json");
xhttp.setRequestHeader("Authorization", 'OAuth2 '+'~{ch://OCAC_2sRo3vI7iJzI5E9/$.access_token}');
xhttp.send(JSON.stringify({ "filters": {"project-number":number} }));
xhttp.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {
let data = JSON.parse(this.response);
if(data && data.filtered){
resData.push(data.itemss0].item_id);
}
console.log(data);
console.log(resData);
}
};
});
}

 

Based on the support page mentioned here, we cannot make outbound API calls in code task.


Leave a Reply