Skip to main content

Error "Could not find field \\"fields\\" in the request body" in PHP CURL request


Hello!

I’m trying write php function to update existing record in my airtable using CURL. In documentation wroten it should using PATCH method.

My funcion code is:

function updateairtablerecord(_airtable_app,_tablename, _api, _record) {
$ch = curl_init();
url='https://api.airtable.com/v0/'._airtable_app.’/’._tablename.'/'._record->id;
fields=_record->fields;
print_r($fields);
echo “
”;
$data=json_encode($fields);
$data=’{“fields”: ‘.$data.’}’;
print_r($data);

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$_api));
$r = curl_exec($ch);
curl_close($ch);
return $r;

// after its prints using print_r in body of program
}

after executing it returns:

stdClass Object ( [Deadline] => 2020-02-20 [Notice] => 2020-02-05 [Header] => Taskheader2 [Complete] => 1 [Notes] => Task notice2 )
“fields”: {“Deadline”:“2020-02-20”,“Notice”:“2020-02-05”,“Header”:“Taskheader2”,“Complete”:true,“Notes”:“Task notice2”}

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

I can’t understand what i do incorrectly. If i clear all strings shamanish manipulations with fields variable and trying to send _record, it not working too…

Help me pls with it problem!

This topic has been closed for replies.