Help

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

3310 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Pierre_Bondu
4 - Data Explorer
4 - Data Explorer

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 !

5 Replies 5
Andrew_Johnson1
8 - Airtable Astronomer
8 - Airtable Astronomer

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…

Pierre_Bondu
4 - Data Explorer
4 - Data Explorer

For more details, here is my code. The “GetEvent” function works great :slightly_smiling_face:
#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.
}

Elvan_Erkaya
4 - Data Explorer
4 - Data Explorer

Hi everyone,
I have the similar problem, but I could not seem to figure it out. I am not using curl but I am using the npm airtable package with node.js.

Below is the error code I get from console.

Error: Request failed with status code 422
at createError (createError.js:17)
at settle (settle.js:19)
at XMLHttpRequest.handleLoad (xhr.js:78)

Airtable error: {“error”:{“type”:“INVALID_REQUEST_MISSING_FIELDS”,“message”:“Could not find field “fields” in the request body”}}

Here is my code.

Could somebody please explain me the error of my code? Thanks a lot!

var Airtable = require('airtable');
Airtable.configure({
    endpointUrl: 'https://api.airtable.com',
    apiKey: '####'
});
var base = Airtable.base('#####');
const axios = require('axios');
var airtable_write_endpoint = "https://api.airtable.com/v0/####v/Table%201?api_key=####";
var form = document.querySelector("#bize-ulasin");

axios.post(airtable_write_endpoint, {
         "fields": {
            "AdSoyad": document.getElementById("#Ad-Soyad"),
            "Email": document.getElementById("#Email"),
            "Telefon": document.getElementById("#Telefon"),
            "Konu": document.getElementById("#Konu"),
            "Mesaj": document.getElementById("#Mesaj"),
            "Ortam": "Websitesi"
        }
    })
    .then(function(response) {
    console.log(response);
        })
        .catch(function(error) {
        console.log(error);
    });

<form action="https://api.airtable.com/v0/####/Table%201?api_key=####" id="bize-ulasin" method="POST">
                  <div className="form-group row">
                          <input type="text" name="AdSoyad" className="form-control" placeholder="Ad-Soyad*" id="Ad-Soyad" required/>  </div> 
div className="form-group row">

                      <input type="email" name="Email" className="form-control" placeholder="E-mail*" id="Email"
                             
                             required/>

              </div>
              <div className="form-group row">

                  <input type="number" name="Telefon" className="form-control" placeholder="Telefon*" id="Telefon"
                         required/>

              </div>
                  <div className="form-group row">
                      <label placeholder="Konu*"></label>

                      <select className="form-control" name="Konu" placeholder="" id="Konu">
                          <option>Soru</option>
                          <option>Öneri</option>
                          <option>Şikayet</option>
                      </select>

                  </div>
              <div className="form-group row">

                      <textarea className="form-control" name="Mesaj" id="Mesaj" rows="3" placeholder="Mesaj"
                        required/>

              </div>
              <div className="form-group row">
                  <div className=" text-center">
                      <button type="submit" className="btn doggo-btn-scd doggo-color-main-bg">GÖNDER</button>
                  </div>
              </div>
          </form>
Nathan_Harvey
4 - Data Explorer
4 - Data Explorer

The solution to this is in the duplicate (post-with-alteryx-returning-validation-and-fields-not-found-errors):

set the header to be

Content-type: application/json

Thanks @Nathan_Harvey, I’d used ‘application-json’ instead of ‘applicaiton/json’ and was getting confused by the error message. You solved it for me!