I have created rest api for customers who update the one customer field. This is below code to updaye customer by REST API Any other way to update the customer by REST API without the pass mandatory fields ?
I HAVE TO UPDATE ONLY ONE FIELD taxvat
for that I have to forcefully passed the firstname,lastname,email,websiteId,email and id.
Any trick in REST API to update the one field without passing all mandatory fields or just passing by email or customer id ?
Note: Mandatory fields have values so why rest api throw message that firstname,lastname and email is missing.
<?php
$url= "https://example.com/rest";
$accessToken= 'asadsadrjt5l46jl45nmnfsdfd';
$setHeaders = array('Content-Type:application/json','Authorization:Bearer '.$accessToken);
$url = $url."/V1/customers/27";
$apiUrl = str_replace(" ","%20",$url);
$ch = curl_init();
$customerData = [
'customer' => [
'id' => 27,
'email'=>'[email protected]',
"firstname"=>"Identify",
"lastname"=>"Identify",
"taxvat" => "1982",
"websiteId" => 1
]
]
];
$data_string = json_encode($customerData);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $setHeaders);
$token = curl_exec($ch);
$response = json_decode( curl_exec($ch), TRUE);
curl_close($ch);
echo "<pre>";print_r($response);exit;
?>