I have simple javascript in parse's cloud code to collect list of email addresses which I add to my httprequest in cloudcode to send to mandrill.
However, the http request seem to have extra backslashes(\) causing mandrill to reject the request. Nevertheless, then I print the same string in alert box in cloude code, it prints it perfectly. I have compared the httprequest log to hardedcoded email list request (that request succeeds), and hence I know about these extra chars.
I am really not sure what is happening, any pointers would be highly appreciated.
I have snippets of my code and parts of log as below:
Cloud code to collect email in a string: . .
var query1 = new Parse.Query(Parse.User);
query1.equalTo("emailVerified", true);
query1.find({
success: function (object)
{
var emaillink;
for (var i=0;i<object.length;i++)
{
var testresult=object[i];
if(i==0)
{
emaillink="\'"+testresult.get("email")+"\', \"name\" : \'"+testresult.get("username")+"\', \"type\" : \'to\' },";
}
else
{
emaillink=emaillink+"{ \"email\" : \'"+testresult.get("email")+"\', \"name\" : \'"+testresult.get("username")+"\', \"type\" : \'to\' },"
}
}
emaillink = emaillink.substring(0, emaillink.length - 2);
alert(emaillink);
Parse.Cloud.httpRequest({...
cloudcode to add these emails to httprequest format for mandrill:
. . .
"to": [
{ "email": emaillink
}
]
. .
log of alert:
##################################################
# Alert #
##################################################
# #
# 'abc@gmail.com', "name" : 'abc 1 #
# ', "type" : 'to' },{ "email" : 'abcdefghijklnm #
# 101@gmail.com', "name" : 'abcdefgh', "type" : #
# 'to' },{ "email" : 'qwertyiopau@yahoo.com', "n #
# ame" : 'qwertyiop', "type" : 'to' #
# #
# [ OK ] #
# #
##################################################
log in cloudcode of the httprequest:
..."text":"[{\"email\":\"'abc@gmail.com', \\\"name\\\" : 'abc 1', \\\"type\\\" : 'to' },{ \\\"email\\\" : 'abcdefghijklnm101@gmail.com', \\\"name\\\" : 'abcdefghijklnm', \\\"type\\\" : 'to' },{ \\\"email\\\" : 'abcdefghijklnm@yahoo.in', \\\"name\\\" : 'abcdefghijklnm', \\\"type\\\" : 'to'\",\"status\":\"invalid\",\"_id\":\"18523fc4a3d24a1398c303972af47cd8\",\"reject_reason\":null}]","data":[{"email":"'abc@gmail.com', \"name\" : 'abc', \"type\" : 'to' },{ \"email\" : 'abcdefghijklnm101@gmail.com', \"name\" : 'abcdefghijklnm', \"type\" : 'to' },{ \"email\" : 'abcdefghijklnm@y.in', \"name\" : 'abcdefghijklnm', \"type\" : 'to'","status":"invalid","_id":"18523fc4a3d24a1398c303972af47cd8","reject_reason":null}],"buffer":{"0":91....
please ignore the emails, i have replaced actual emails with some random email values. The values are correct, that I have checked.
It is just these extra \ that I can't explain. Any help is highly appreciated. Thanks