Ubidots Community

[SOLVED] Collections - 404 Error

I am trying to use the collections API function for my Arduino / Fona. I am getting a 404 error. I see the documentation for this function in CURL but I cannot find an example of how the JSON request should be formed in C.

Here is the relevant section of code:
var="[{“variable”: xxxvariablexxxxx, “value”: 50 }, {“variable”: xxxvariable2xxx, “value”:22 }]"; //value is the sensor value & GPS
num=var.length();
le=String(num); //this is to calcule the length of var
Serial.print(F("Start the connection to Ubidots: "));
if (SendATCommand("AT+CIPSTART=“tcp”,“things.ubidots.com”,“80"”,‘C’,‘T’)) {
Serial.println(F(“Connected”));
}
Serial.print(F("Begin to send data to the remote server: "));
if (SendATCommand(“AT+CIPSEND”,’\n’,’>’)) {
Serial.println(F(“Sending”));
}
fona.println(F(“POST /api/v1.6/collections/values HTTP/1.1”)); // Replace with your ID variable
fona.println(F(“Host: things.ubidots.com”));
fona.println(F(“X-Auth-Token: xxxmyTokenxxx”)); //in here, you should replace your Token
fona.println(F(“Content-Type: application/json”));
fona.print(F("Content-Length: "));
fona.println(le);
fona.println();
fona.println(var);
fona.println();
fona.println((char)26); //This terminates the JSON SEND with a carriage return

Hello, please try putting the variable id’s into double quotes:

var="[{\"variable\": \"xxxvariablexxxxx\", \"value\": 50 }, {\"variable\": \"xxxvariable2xxx\", \"value\":22 }]"; //value is the sensor value & GPS
num=var.length();
le=String(num); //this is to calcule the length of var
Serial.print(F("Start the connection to Ubidots: "));
if (SendATCommand("AT+CIPSTART=\"tcp\",\"things.ubidots.com\",\"80\"",'C','T')) {
Serial.println(F("Connected"));
}
Serial.print(F("Begin to send data to the remote server: "));
if (SendATCommand("AT+CIPSEND",'\n','>')) {
Serial.println(F("Sending"));
}
fona.println(F("POST /api/v1.6/collections/values HTTP/1.1")); // Replace with your ID variable
fona.println(F("Host: things.ubidots.com"));
fona.println(F("X-Auth-Token: xxxmyTokenxxx")); //in here, you should replace your Token
fona.println(F("Content-Type: application/json"));
fona.print(F("Content-Length: "));
fona.println(le);
fona.println();
fona.println(var);
fona.println();
fona.println((char)26); //This terminates the JSON SEND with a carriage return

It works! Hackmed you Rock!

Don’t know why I did not see this collections feature in the API before but this should significantly reduce the time my device spends reporting data.

1 Like