How to Re-set customer account password through Rest Api?

Which fields should we send in Api body to reset the password?

有帮助吗?

解决方案

You can achieve below way:

Step 1: Send a reset token to customer mail by using below API. By default magento send a reset link password link in mail. For that customer will redirected to web view to reset password. Although little modification of email template we can send the reset token through mail as shwn below.

Api details:

url : http://example.com/rest/V1/customers/password    
Http method : PUT
Http header  : Content-Type application/json
Json Body : {"email":"test@gmail.com","template":"email_reset"} // email should be a valid email address as token will be sent there.

Email template modification[YourPackage/YourTheme/Magento_Customer/email/password_reset_confirmation.html]

   <!--
    /**
    * Copyright © Magento, Inc. All rights reserved.
    * See COPYING.txt for license details.
    */
    -->
    <!--@subject {{trans "Password Reset Confirmation for %name" name=$customer.name}} @-->
    <!--@vars {
    "var customer.name":"Customer Name",
    "var this.getUrl($store, 'customer/account/createPassword/', [_query:[id:$customer.id, token:$customer.rp_token]])":"Reset Password URL"
    } @-->
    {{template config_path="design/email/header_template"}}

    <p class="greeting" style="font-weight: bold;
    font-size: 25px;
    margin-bottom: 25px;
    margin-top: 5px;
    line-height: 28px;">{{trans "%name," name=$customer.name}}</p>
    <p>{{trans "There was recently a request to change the password for your account."}}</p>
    <p>{{trans "If you requested this change, your password reset token is:"}}</p>

    <table class="button" width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td>
            <table class="inner-wrapper" border="0" cellspacing="0" cellpadding="0" align="center">
                <tr>
                    <td align="center">
                        {{trans "%token" token=$customer.rp_token}}
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    </table>

    <p>{{trans "If you did not make this request, you can ignore this email and your password will remain the same."}}</p>

    {{template config_path="design/email/footer_template"}}

Step2: By the use of reset token and with help below API:

Api details:

url : http://example.com/rest/V1/customers/resetPassword    
Http method : POST
Http header  : Content-Type application/json
Json Body : {"email":"test@gmail.com","resetToken":"token received in mail","newPassword":"new password"}

Hope this help you.

许可以下: CC-BY-SA归因
scroll top