cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2.2.2 REST API - I need to change the customer password using REST API

SOLVED

Magento 2.2.2 REST API - I need to change the customer password using REST API

Magento rest API - I need to change the customer password using REST API.

In POSTMAN application

url action :: PUT

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

And i passed integration token in header.

Authorization :: Bearer <Token Value>
Content-Type :: application/json

And In Form-data

customerId :: <customerId>currentPassword :: <currentPassword>newPassword :: <newPassword>

webapi.xml code is

<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>

But it give me error ::

 

{"message":"Decoding error: \nUnable to unserialize value.\n#0 /var/www/html/rb-dev/vendor/magento/framework/Webapi/Rest/Request/Deserializer/Json.php(64): Magento\Framework\Serialize\Serializer\Json->unserialize('------WebKitFor...')\n#1 /var/www/html/rb-dev/vendor/magento/framework/Webapi/Rest/Request.php(141): Magento\Framework\Webapi\Rest\Request\Deserializer\Json->deserialize('------WebKitFor...')\n#2 /var/www/html/rb-dev/vendor/magento/module-webapi/Controller/Rest/InputParamsResolver.php(91): Magento\Framework\Webapi\Rest\Request->getBodyParams()\n#3 /var/www/html/rb-dev/vendor/magento/module-webapi/Controller/Rest.php(322): Magento\Webapi\Controller\Rest\InputParamsResolver->resolve()\n#4 /var/www/html/rb-dev/vendor/magento/module-webapi/Controller/Rest.php(239): Magento\Webapi\Controller\Rest->processApiRequest()\n#5 /var/www/html/rb-dev/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))\n#6 /var/www/html/rb-dev/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Webapi\Controller\Rest\Interceptor->___callParent('dispatch', Array)\n#7 /var/www/html/rb-dev/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Webapi\Controller\Rest\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))\n#8 /var/www/html/rb-dev/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php(39): Magento\Webapi\Controller\Rest\Interceptor->___callPlugins('dispatch', Array, Array)\n#9 /var/www/html/rb-dev/vendor/magento/framework/App/Http.php(135): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))\n#10 /var/www/html/rb-dev/generated/code/Magento/Framework/App/Http/Interceptor.php(24): Magento\Framework\App\Http->launch()\n#11 /var/www/html/rb-dev/vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Http\Interceptor->launch()\n#12 /var/www/html/rb-dev/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))\n#13 {main}","trace":null}

Anyone have any idea? Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Magento 2.2.2 REST API - I need to change the customer password using REST API

Hi @aditya_shah

 

I have seen you are passing parameter in Form-Data that might be the reason you are facing this kind of issue instead of Form-data select parameter as RAW  - then choose  JSON(application/json) !

 

Also you are passing customerId=146   in URL - so you actually don't need to pass this in parameter - as it is for that specific user only so !!

 

Below i am sharing exact endpoint with parameters which you need to pass in POSTMAN.

 

Endpoint - http://magento.host/rest/V1/customers/me/password?customerId=146

 

Headers - Authorization bearer your_access_token

Content - Type - application/json

 

Body : 

 

 

{
  "currentPassword": "current_password",
  "newPassword": "new_password"
} l

 

 

Method Name : PUT

 

For more reference refer this link - https://devdocs.magento.com/swagger/#!/customerAccountManagementV1/customerAccountManagementV1Change...

 

It will work !!

 

 

 

if issue solved,Click Kudos & Accept as Solution

View solution in original post

2 REPLIES 2

Re: Magento 2.2.2 REST API - I need to change the customer password using REST API

Hello @aditya_shah

 

you need to pass data into json format

 

Change customer passwordV1/customers/me/passwordPUTAuthorization : Bearer { Customer Unique key }
Content-Type : application/json
 {
"currentPassword": "123123",
"newPassword": "123456"
}
Success : true
Error : message

Hope it will help you.

 

If work then marks as solution.


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Magento 2.2.2 REST API - I need to change the customer password using REST API

Hi @aditya_shah

 

I have seen you are passing parameter in Form-Data that might be the reason you are facing this kind of issue instead of Form-data select parameter as RAW  - then choose  JSON(application/json) !

 

Also you are passing customerId=146   in URL - so you actually don't need to pass this in parameter - as it is for that specific user only so !!

 

Below i am sharing exact endpoint with parameters which you need to pass in POSTMAN.

 

Endpoint - http://magento.host/rest/V1/customers/me/password?customerId=146

 

Headers - Authorization bearer your_access_token

Content - Type - application/json

 

Body : 

 

 

{
  "currentPassword": "current_password",
  "newPassword": "new_password"
} l

 

 

Method Name : PUT

 

For more reference refer this link - https://devdocs.magento.com/swagger/#!/customerAccountManagementV1/customerAccountManagementV1Change...

 

It will work !!

 

 

 

if issue solved,Click Kudos & Accept as Solution