1

Using Magento, API. I need to create an API for customer send forget password. I found the page that allows to customer send e-mail for request change password but I don't how to use this page for web service.

enter image description here

asked Aug 13, 2018 at 4:28

2 Answers 2

1
 <?php 
 require_once('baseurl.php');
error_reporting(E_ALL ^ E_NOTICE); 
$userData = array("username" => "", "password" => "");
$ch = curl_init($baseUrl . "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);
 $url=$baseUrl . "rest/V1/customers/password?email=".$emailId."&template=email_reset&websiteId=1";
 //echo $url;
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));
 $result = curl_exec($ch);
 if($result=='true'){
 $response='{
 "status":"true",
 "message":"Password reset link has been sent to your email id"
 }';
 echo $response;
 }
 else{
 $response='{
 "status":"false",
 "message":"This email address is not registered"
 }';
 echo $response;
 }
answered Aug 13, 2018 at 5:19
4
  • I am using this way for forget password api for mobile app Commented Aug 13, 2018 at 5:29
  • I got this message : "message": "Too many password reset requests. Please wait and try again or contact %1. Commented Aug 13, 2018 at 5:49
  • Set from store->configuration->customer->customer configuration->password option->Min Time Between Password Reset Requests Commented Aug 13, 2018 at 6:15
  • Try after 2 hours it will work Commented Aug 13, 2018 at 6:16
1

webapi.xml

<route url="/V1/customers/me/password" method="PUT">
 <service class="Magento\Customer\Api\AccountManagementInterface" method="changePasswordById"/>
 <resources>
 <resource ref="self"/>
 </resources>
 <data>
 <parameter name="customerId" force="true">%customer_id%</parameter>
 </data>
</route>

url :: action - PUT

http://127.0.0.1/magento.host/rest/V1/customers/me/password?customerId=160

Headers ::

Authorization Bearer <Admin Token>
Content-Type application/json

Body> raw> JSON(application/json) ::


{
 "currentPassword": "aditya@123",
 "newPassword": "admin@123"
}

Output

It will change customer password, need to pass current and new password in body.

answered Aug 13, 2018 at 5:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.