Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

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

1367 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Anatoly_Starodu
4 - Data Explorer
4 - Data Explorer

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!

0 Replies 0