Impossible to create a record - "Could not find field \"fields\" in the request body"


#1

Hello everybody,

I’m trying to use Airtable API for the first time with my arduino Yun and I encontered a problem with creating record.
When I use my program, I get the following error : "error":{“type”:“INVALID_REQUEST_MISSING_FIELDS”,“message”:“Could not find field “fields” in the request body”}}.`
I think it’s just a formatting problem but I can’t find where and I did find anything helpful on the internet (which make me think my problem is very idiot :blush: )

What can I do ? Thanks in advance !


#2

You have not added the “fields” attribute to the body of your request.

Also the “body” parameter is expecting a JSON object.
Your curl request should look like

-d ‘{
“fields”: {
“gender”: “male”
}
}’

It can be adapted for any language though…


#3

For more details, here is my code. The “GetEvent” function works great :slight_smile:
#include <ArduinoJson.h>
#include <Process.h>
int Creer = 0;
String ApiKey = “XXX”;

void GetEvent(String IdEvent) {

Serial.println("-----");
Serial.println("‘GetEvent’ démarré");
Process r; // Create a process and call it ‘r’
r.begin(“curl”);
r.addParameter("-v");
//r.addParameter("-I");
r.addParameter(“https://api.airtable.com/v0/appfqkj7sz4JgkmZJ/Evenement/” + IdEvent + “?api_key=” + ApiKey);
r.run();
// A process output can be read with the stream methods
while (r.available() > 0) {
char c = r.read();
Serial.print©;
}
Serial.println("‘LireEvent’ - rtour reçu");
//Ensure the last bit of data is sent.
Serial.flush();
delay(5000);
}

void CreateEvent(String NomEvnt, String TypeEvnt, int MesureHumidite)
{
Serial.println("-----");
Serial.println("‘CreateEvent’ démarré");
Process q;
q.begin(“curl”);
q.addParameter("-XPOST");
q.addParameter(“https://api.airtable.com/v0/appfqkj7sz4JgkmZJ/Evenement?api_key=” + ApiKey);
q.addParameter("-v");
q.addParameter(“Content-Type: application/json”);
q.addParameter("-d");
JsonEvenement = “{“fields”:{“Name”:”";
JsonEvenement += NomEvnt;
JsonEvenement += “”,“Type événement”:"";
JsonEvenement += TypeEvnt;
JsonEvenement += “”,“Mesure - humidité”:";
JsonEvenement += MesureHumidite;
JsonEvenement += “,“Pot”:”;
JsonEvenement += “[“recJiYcOz0lS8vOsN”]”;
JsonEvenement += “,“Sonde - Mesure”:”;
JsonEvenement += “[“rectLngEvcaZA9CR3”]”;
JsonEvenement += “,“Date / Heure”:”";
JsonEvenement += “2017-05-08T10:19:00.000Z”;
JsonEvenement += “”}";
//JsonEvenement += ““typecast”:”";
//JsonEvenement += “true”;
//JsonEvenement += “}’”;
q.addParameter(JsonEvenement);
Serial.println(JsonEvenement);
Serial.println();
q.run();
while (q.available() > 0) {

char d = q.read();
Serial.print(d);
}
Serial.println("‘CreateEvent’ - retour reçu");
//Ensure the last bit of data is sent.
Serial.flush();
delay(5000);
}

void setup() {
// Initialize Bridge
Bridge.begin();

// Initialize Serial
Serial.begin(9600);

// Wait until a Serial Monitor is connected.
while (!Serial);

// run various example processes
//runCurl();
CreateEvent(“Test646464”, “Mesure - Trop sec”, 140);
GetEvent(“recJZJ2TUM5huXBVq”);
}

void loop() {
// Do nothing here.
}