Here's the code:
var dbId = "xxx";
var masterKey = "yyy";
try {
var XHRResponse = XHR.send("GET", "https://api.appery.io/rest/1/db/users/", {
"headers": {
"X-Appery-Database-Id": dbId,
"X-Appery-Master-Key": masterKey
}
});
var nUsers = XHRResponse.body.length;
console.log("Number of users = " + nUsers); //this works
if (nUsers) {
for (var i = 0; i < nUsers; i++) {
var email = XHRResponse.body["email"];
if (XHRResponse.status == 200 && email) {
console.log(email); // this works
Code: Select all
// if I comment out the following POST, this lists all the users emails as expected. But if I add the following sendgrid post, it sends one email correctly then I get an error: "Cannot read property 'email' of undefined code: undefined"
var XHRResponse = XHR.send("POST", "[url=https://api.sendgrid.com/api/mail.send.json]https://api.sendgrid.com/api/mail.sen...[/url]", {
"parameters": {
"api_user": "ginoborland",
"api_key": "*********",
"to": email,
"toname": "",
"subject": "Time sure does fly...",
"text": "Take time now to connect with...[url=http://timeflies.app.appery.io]http://timeflies.app.appery.io[/url]",
"from": "a href="mailto:ginoborland@hotmail.com" rel="nofollow"ginoborland@hotmail.com/a"
}
});
} // if email
} // for
} // if nUsers
} catch (e) {
console.log("message: " + e.message + "\ncode: " + e.code); //If something goes wrong, error message appears
//response.success("message: " + e.message + "\ncode: " + e.code); //If something goes wrong, error message appears
}