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.
Evince Development
8777 silver badges20 bronze badges
asked Aug 13, 2018 at 4:28
2 Answers 2
<?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
-
I am using this way for forget password api for mobile appMahendra– Mahendra2018年08月13日 05:29:27 +00:00Commented Aug 13, 2018 at 5:29
-
I got this message :
"message": "Too many password reset requests. Please wait and try again or contact %1.Bong Channarith– Bong Channarith2018年08月13日 05:49:22 +00:00Commented Aug 13, 2018 at 5:49 -
Set from store->configuration->customer->customer configuration->password option->Min Time Between Password Reset RequestsMahendra– Mahendra2018年08月13日 06:15:51 +00:00Commented Aug 13, 2018 at 6:15
-
Try after 2 hours it will workMahendra– Mahendra2018年08月13日 06:16:16 +00:00Commented Aug 13, 2018 at 6:16
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
default