I’ve got a cURL PATCH request in order to update a record, however I seem to be getting this error:
{
"error": {
"type": "INVALID_REQUEST_MISSING_FIELDS",
"message": "Could not find field \\"fields\\" in the request body"
}
}
This is my current cURL request, I am using PHP:
<?php
// get cURL resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, 'https://api.airtable.com/v0/appmAdTUWbbY2vitV/Members/recl0qsFKY2dkR1NR');
// set method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// set headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json; charset=utf-8',
'Cookie: brw=brwjOwXWWJ95PfnJr',
]);
// json body
$json_array = [
'records' => [
[
'id' => 'recl0qsFKY2dkR1NR',
'fields' => [
'Rank' => 'Captain'
]
]
]
];
$body = json_encode($json_array);
// set body
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
// send the request and save response to $response
$response = curl_exec($ch);
// stop if fails
if (!$response) {
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}
echo 'HTTP Status Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL;
echo 'Response Body: ' . $response . PHP_EOL;
// close curl resource to free up system resources
curl_close($ch);
Note, I’ve deliberately left out my API key.
I’ve tried searching the web, but nothing has yet worked! Please help! I do not know how to use the bundled .js
API, which is why I am doing it this way.