2

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;
?>
3
  • 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.
    – Diana
    Commented Feb 12, 2021 at 6:56
  • @DianaBotean ok thanks Commented Feb 12, 2021 at 13:57
  • imho this is the answer not a comment on your question. Maybe it's an idea to post it as an answer and accept it? Commented Feb 12, 2021 at 23:33

1 Answer 1

0
+100

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.

1
  • Can you please post custom API example so that woruld be great help.I accepted answer Commented Feb 16, 2021 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.