Internal Error 500 over Http Post request

I am using Java to make some requests to your api. When I make Get requests everything work ok. I get the responses with no errors, but when I try to make a Post request I keep getting 500 error. I include the code below:

String param = ("{\"functions\": [{\"type\":\"UpdateSensor\",\"params\":"
+ "{\"name\":\"MyAwesomeTest\"}}],\"selection\": {"
+ "\"selectionType\":\"registered\",\"selectionMatch\":\"\"}"
+ ",\"thermostat\": {\"settings\":{\"identifier\":\"{id_name_here}\"}}}");

String url = "https://api.ecobee.com/1/thermostat?f...=";
URL myurl = new URL(url);

HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", "x...x-java-client");
con.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
con.setRequestProperty("Authorization", "Bearer " + authorizationToken);
con.setDoOutput(true);
con.setDoInput(true);

DataOutputStream output = new DataOutputStream(con.getOutputStream());
output.writeBytes(param);
output.close();

DataInputStream input = new DataInputStream( con.getInputStream() );
for( int c = input.read(); c != -1; c = input.read() )
System.out.print( (char)c );
input.close();

I have tried using url with or without &body=, same error occured. I have also tried sending the params encoded URLEncoder.encode() still no proper response. Thanks in advance,

Bill.
1 person has
this question
+1
Reply
  • ScottF (Official Rep) May 12, 2015 11:00
    Hi Bill,
    It's quite difficult for us to see what you are doing exactly, if you could post your actual request payload and the response you are getting it might help. It is not our policy to debug 3rd party code.

    Having said that I can see a couple of things wrong without that request/response data.

    1. The name of the function is "updateSensor", note the lowercase "u".
    2. You did not supply two of the three required fields in the sensor object i.e. deviceId, and sensorId. Take a look at the API docs here: https://www.ecobee.com/home/developer...
    3. Your request seems to have a thermostat object too, which is unnecessary, again take a look at the API doc link in #2 above and at the sample request there.

    Hopefully this helps, but if not please post your request/respones JSON payloads here, with your identifier obfuscated, so we can try to help further.

    Scott
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I used curl for testing:
    curl -H "Content-Type: application/json" -H "Authorization: Bearer my_Token_Here" -d "%7B%0A%20%20%20%20%22selection%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22selectionType%22%3A%20%22registered%22%2C%0A%20%20%20%20%20%20%20%20%22selectionMatch%22%3A%20%22%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22thermostat%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22settings%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22serviceRemindMe%22%3A%20%22true%22%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D" "https://api.ecobee.com/1/"https://api...""
    This post request is equal to :
    {
    "selection": {
    "selectionType": "registered",
    "selectionMatch": ""
    },
    "thermostat": {
    "settings": {
    "serviceRemindMe": "true"
    }
    }
    }
    All of the sudden I got a response(!?!)
    {
    "status": {
    "code": 0,
    "message": ""
    }
    }
    which was ok.
    So I guess it's my bad, I will look for probable mistakes and I will let you know.

    Thanks,
    Bill.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned

  • I found the error. I had to specify to the server about the encoding, at some point inside the code I was encoding the parameters.
    Thanks again Scott.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly happy, confident, thankful, excited indifferent, undecided, unconcerned