apipostethernetintel-galileo

How to correctly adapt this POST resquest to plot.ly REST API?


I'm using Arduino Galileo to plot a graph on plot.ly using REST API. With this code

  client.println("POST /clientresp HTTP/1.1");
  //client.println("Host: 107.21.214.199");
  client.println("Host: plot.ly");
  client.println("User-Agent: Galileo/0.0.1");
  client.print("Content-Length: ");

  int content_length = 276 + username.length() + api_key.length() + temperaturesY.length() + timesX.length();
  client.println(content_length);
  client.println();
  client.print("version=2.3&origin=plot&platform=Galileo&un=");
  client.print(username);
  client.print("&key=");
  client.print(api_key);
  client.print("&args={\"x\":");
  client.print(timesX);
  client.print(",\"y\":");
  client.print(temperaturesY);
  client.print(",\"type\":\"scatter\",\"mode\":\"lines+markers\",\"visible\":true}&kwargs={\"filename\":\"galileo_temperature\",\"fileopt\":\"overwrite\",\"style\":{\"type\":\"line\"},\"layout\":{\"title\":\"Galileo CPU Temperature\"},\"world_readable\":true}");
  client.println();

I'm getting this error:

{"url": "", "message": "", "warning": "", "filename": "", "error": "Missing required POST parameters: platform un key origin args kwargs"}

How to adapt this?


Solution

  • After the code:

    client.println("POST /clientresp HTTP/1.1");
    client.println("Host: plot.ly");
    client.println("User-Agent: Galileo/0.0.1");
    

    Add the content-type header:

    client.println("Content-Type: application/x-www-form-urlencoded");
    

    With it I was able to sucessfuly plot a chart