Hey there, @asg3! Appreciate you reaching out in community - I hear ya on the “new but fun”! 🧠
I’m moving your question to our webhooks forum to hopefully get some more technical eyes on your question.
I think the problem is that output I’m retrieving isn’t in the correct format for Zapier.
The data is output like this:
{"city":"Warren Township","country":"United States"}
{"city":"New York","country":"United States"}
{“city”:”Stamford”,”country”:”United States"}
And Zapier is expecting it to start and end with and brackets, like this:
,{"city":"Warren Township","country":"United States"}
{"city":"New York","country":"United States"}
{“city”:”Stamford”,”country”:”United States"}]
So I tried using a Code by Zapier Zap to pull in the data and convert it into a string, but without success. This is what I tried but it doesn’t work (Error while retrieving: You must return a single object or array of objects.)
return fetch("https://api.iterable.com/api/export/data.json?dataTypeName=emailSend&range=Yesterday", {
mode: 'cors',
headers: { 'x-api-key': 'xxxxxxxxxxxxxxxxxxxxxxx',
'User-Agent' : 'My-App',
'Accept': '*/*', }, })
.then(response => response.text())
.catch(error => console.log('Error while fetching:', error))
callback(error, "output")
let xStr = response.text();
let obj = JSON.parse(xStr);
output = {obj};
I figured out how to pull and transform the data. Using a Code by Zapier Zap with the following JS:
let url = 'https://api.iterable.com/api/export/data.json?dataTypeName=emailOpen&range=Today&onlyFields=email&onlyFields=createdAt&onlyFields=templateId&onlyFields=messageId&onlyFields=campaigniD&onlyFields=contentID'
let iterableData = 'undefined'
let response = await fetch(url, {
method: "GET",
headers: {
'Api-Key': '----------REDACTED----------',
},
});
iterableData = await response.text()
iterableData = iterableData.replace(/\}/g, "},") //Add a "," to the end of each line
iterableData = "[" + iterableData.slice(0, -2) + "]" //Remove the last comma and add bracket
let iterableJSON = JSON.parse(iterableData) //Convert to JSON
output = {iterableJSON}