Zway Noob - HTTP Request

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
StudentInNeedOfHelp
Posts: 3
Joined: 24 Nov 2014 11:05

Zway Noob - HTTP Request

Post by StudentInNeedOfHelp »

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.

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"
                          }]
                     }
            }
        });
    }
});
AJAX code that worked

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"
            }]
        }
    }
});
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.
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Zway Noob - HTTP Request

Post by pofs »

There's currently a restriction in http.request() that prevents it from serializing forms with multi-level fields. So anything under "message" in your request is just ignored.

We've just made an improvement to allow this. It will be available in upcoming 2.0-rc22.

P.S. if your service requires JSON instead of HTTP form (which might be considered from its .json extension), just pass data as JSON.stringify({your object})
Post Reply