Question

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'=>'test@test.com',
        "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;
?>
Was it helpful?

Solution

At @BramHammer's suggestion, I am adding my comment as an answer, in a more visible place, since it is indeed my answer to your question.

I don't think there is such a method in the OOTB Magento REST API or a default workaround. I think your only option is to create and expose a custom method.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top