I have made my research before opening this thread . Here is what I am trying to achieve .
Edit : A bit more context:
Iam building a product management tool for Prestashop CSM. One of the functionalities imply creating products from a table created from user input .
In my web app want to send a POST Api request in XML for each row of a table to a private endpoint ( with authentification ) from a webapp.
I've created the API request query with the right setting for xml bady and performed a request : it works . To be able to send a request for each row I followed the guide here. I created another query called "query3" to trigger query2 (the REST api query ). As for the body of the request i left it empty and referenced {{query3.data}}
and the code to trigger the API query is :
additionalScope: {
data: `[...**the xml body goes here** ]`
}
But in the query3 query there is no way to add an additional scope unlike sql Queries and javascript queries or am I missing something .
here is the full code :
var errors = "";
var total = rows.length;
var rowImported = 0;
var result = '';
function runQuery(i) {
// Update the Status text
result += "Progress: " + (i.toString() + "/" + total.toString());
status1.setValue("pending");
if (i >= rows.length) {
console.log("Finished running all queries");
return;
}
rowImported += 1;
console.log("Running query for row", i);
let cats = rows[i].catégories?rows[i].catégories.split():undefined;
query2.trigger({
additionalScope: {
data: `[...**XML BODY GOES HERE** ]` },
onSuccess: function (data) {
// Make the API request
status1.setValue("completed")
// run query for next rows
// runQuery(i + 1);
},
onFailure: function (error) {
// Update the Errors text
errors += "Found error at line " + i.toString() + ": " + error + "\n\n";
Error.setValue(errors);
runQuery(i + 1);
},
});
}
runQuery(0);
return errors```