I am trying to call an nest api to get room temperature using C code in Arduino.
When I call the api using postman, I get perfect response:
However when I write the code to get the temperature data, I get the following response:
request sent The request is HTTP/1.1 400 Bad Request.
Here is my code, can anyone help me what's wrong with my request:
const char* ssid = "linksys";
const char* password = "XXXXX";
const char* host = "firebase-apiserver07-tah01-iad01.dapi.production.nest.com"; // "developer-api.nest.com"; // "api.github.com";
const int httpsPort = 9553; //443 9553;
String url = "";
.......
.......
.......
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
} else {
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Authorization: Bearer c.SbsgvTBcsJREMOVED_CODE_FOR_SECURITY_REASON\r\n" +
"Content-Type: application/json\r\n\r\n"
);
Serial.println("request sent");
}
Thanks,
Shab
I figured in my case there was a delay in receiving the response. I just had to wait to get the response. And for sure url has to be "/"
String url = "/"
Thanks, Shab
If you're getting a 400, you should check that the URL is actually set to
/
. Your code doesn't have the value of theurl
variable shown.