Zway Noob - HTTP Request
Posted: 24 Nov 2014 11:22
Hello,
I am fairly new to zway. With this said, I am trying to do a HTTP request to a mail service that uses a REST API. I tested a request earlier using AJAX (I know AJAX is client side but it let me know that I am in the right general direction) and it worked fine. However, I cannot get it to work in my function.
AJAX code that worked
What gets me is that the code does not completely break so it is syntactically correct, but I am clearly doing something wrong. Most of the code is the same between the AJAX call and the http.request(), but something must be off. Any help is appreciated and sorry for the sloppy formatting.
I am fairly new to zway. With this said, I am trying to do a HTTP request to a mail service that uses a REST API. I tested a request earlier using AJAX (I know AJAX is client side but it let me know that I am in the right general direction) and it worked fine. However, I cannot get it to work in my function.
Code: Select all
zway.devices[2].instances[0].SensorBinary.data[1].level.bind(function () {
if (this.value === true) {
http.request({
url: "https://mandrillapp.com/api/1.0/messages/send.json",
method: "POST",
data: {
"key": "aKeyThatWorksInAJAX",
"message": {
"text": "A Message to Send",
"subject": "A Subject",
"from_email": "AnEmail",
"from_name": "Person",
"to": [{
"email": "Test",
"name": "User"
}]
}
}
});
}
});Code: Select all
$.ajax({
type: "POST",
url: "https://mandrillapp.com/api/1.0/messages/send.json",
data: {
"key": "AKeyThatWorks",
"message": {
"text": "Test",
"subject": "I need Help",
"from_email": "anEmail@live.com",
"from_name": "APerson",
"to": [{
"email": "anEmail@hotmail.com",
"name": "User"
}]
}
}
});