Update Record using API

HI Everyone,
So I’m having issues updating a record using the API, i can authenticate and retrieve a record fine , but editing or adding doesn’t seem to work. Table has one key column PROPERTY_NO and the table name is bin_data_gla. My php code to edit a record is using CURL and is as follows, ( note CURLOPT_URL has been trimmed to allow this post)

CURLOPT_URL => “?action=edit&object=bin_data_gla&PROPERTY_NO=15117”,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => “”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => “POST”,
CURLOPT_HTTPHEADER => array(
“Content-Type: application/json”,
$xaut
),
));

$response2 = curl_exec($curl2);

$err = curl_error($curl2);
if ($err) {
echo “cURL Error #:” . $err;
} else{
echo “cURL Return :

”;
$jsonObj = json_decode($response2);
$regs = $jsonObj->links;
var_dump($jsonObj);
echo “



”;
print_r($regs);
}

curl_close($curl2);



The response i get is

cURL Return :

NULL

  1. If you have enabled security, you need to login with JWT first. I hope your $xaut contains the correct data, note that the header should be “X-Authorization”.
  2. You use “Content-Type: application/json” but the data should be posted to API like form data.
  3. In your code there is no data to edit. (Note that the action=edit is for updating the record, not for getting a record to edit.)
    See the topic REST API in the help file for more information.

Hi, thanks for your questions / comments.

I already have JWT and authentication working, i just left tat code out as that part is all working and didn’t want extra code confusing the issue.

I have changed the content type to Content-Type: text/html, still no difference.

And the record im editing does exist as i can do an action=view with my separate view code and it returns the data. Im not sure why you say there is no data to edit?

Any other ideas?

  1. Your data is not text/html. In fact, you do not need to provide the content-type.
  2. In your code above, you provided PROPERTY_NO=15117 which locates the record to edit, but you provided no data to edit, e.g. you can provide
    CURLOPT_POSTFIELDS => “field1=xxx&field2=yyy”

Got it to work, for anyone else interested here is my edit code

curl_setopt_array($curl2, array(
CURLOPT_URL => “?action=edit&object=bin_data_gla”,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => “”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_CUSTOMREQUEST => “POST”,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => “PROPERTY_NO=15125&binserial=55555555555”,
CURLOPT_HTTPHEADER => array(
$xaut
),
));

$response2 = curl_exec($curl2);

$err = curl_error($curl2);
if ($err) {
echo “cURL Error #:” . $err;
} else{
echo “cURL Return :

”;
$jsonObj = json_decode($response2);
$regs = $jsonObj->links;
var_dump($jsonObj);
echo “



”;
print_r($regs);
}