Any once please help me out for overwrite the REST api in magento 2.3 please describe with example.
Magento 2.3 – How to Overwrite Customer Registration REST API
apimagento2rest
Related Solutions
So @user2636834 did you figure this one out already?
I remember when I was setting up a test scenario that I got the sames error(s). Seemed that I didn't have Oauth installed :O. So in short I did (running Ubuntu and following these instructions, also running into this error):
pecl install oauth
Then add extension=oauth.so
to php.ini
's "Dynamic Extensions" section.
Then restart Apache
I tried the examples from the Magento site and got an error from the API:
"Invalid auth/bad request"
I had to add a 'Accept' => '*/*'
header to the $oauthClient->fetch()
call. After that it worked all just fine.
Hope you can get things running if you hadn't already.
Create new customer
$userData = array("username" => "admin", "password" => "admin123"); $ch = curl_init("http://magento213/index.php/rest/V1/integration/admin/token"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData)))); $token = curl_exec($ch); $customerData = [ 'customer' => [ "email" => "user@example.com", "firstname" => "John", "lastname" => "Doe", "storeId" => 1, "websiteId" => 1 ], "password" => "Demo1234" ]; $ch = curl_init("http://magento213/index.php/rest/V1/customers"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($customerData)); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token))); $result = curl_exec($ch); $result = json_decode($result, 1); echo '<pre>';print_r($result);
//For update
$customerData = [ 'customer' => [ 'id' => 10, "email" => "user@example.com", "firstname" => "John2", "lastname" => "Doe2", "storeId" => 1, "websiteId" => 1 ], "password" => "Demo1234" ]; $ch = curl_init("http://magento213/index.php/rest/V1/customers/10"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($customerData)); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token))); $result = curl_exec($ch); $result = json_decode($result, 1); echo '<pre>';print_r($result);
Best Answer
You need to create a webapi.xml file under etc folder within your custom module
webapi.xml
You need to define interfaces same as AccountManagementInterface of customer module. I hope it will work. Let me know if you need further help :)