1

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.

4
  • How do you get your token? for /customers/me endpoints it should be generated from integration/customer/token with that customer credentials. Passing customerId in query won't work as magento will disregard it, otherwise you would be able to log in to your account and simply change password to any other customer.
    – Zefiryn
    Commented May 12, 2018 at 11:01
  • I generated token using http://127.0.0.1/rb-dev/index.php/rest/V1/integration/customer/token?username=###&password=### Commented May 12, 2018 at 14:03
  • copy paste your request body with dummy values Commented May 12, 2018 at 16:21
  • In POSTMAN Body form-data Key and Value customerId => 123 currentPassword => test@123 newPassword => test@345 Commented May 14, 2018 at 5:01

1 Answer 1

8

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.