4

I am trying to authenticate via token based authentication. I am using 'Advanced REST client' extension in chrome to test the API.

this is my request

http://local.nomo/index.php/rest/V1/integration/admin/token and my headers

Content-Type: application/json
Cookie: PHPSESSID=r9p1tjg450ogd6ime05jsleal0
Content-Length: 39
Source message

POST /index.php/rest/V1/integration/admin/token HTTP/1.1
 HOST: local.nomo
 content-type: application/json
 cookie: PHPSESSID=r9p1tjg450ogd6ime05jsleal0
 content-length: 39

 username='test'&password='test'

I always get this error on in response:

{
"message": "Decoding error: Decoding failed: Syntax error #0 /var/www/nomo/vendor/magento/framework/Json/Decoder.php(20): Zend_Json::decode('username='test'...') #1 /var/www/nomo/vendor/magento/framework/Webapi/Rest/Request/Deserializer/Json.php(49): Magento\Framework\Json\Decoder->decode('username='test'...') #2 /var/www/nomo/vendor/magento/framework/Webapi/Rest/Request.php(131): Magento\Framework\Webapi\Rest\Request\Deserializer\Json->deserialize('username='test'...') #3 /var/www/nomo/vendor/magento/framework/Webapi/Rest/Request.php(190): Magento\Framework\Webapi\Rest\Request->getBodyParams() #4 /var/www/nomo/var/generation/Magento/Framework/Webapi/Rest/Request/Proxy.php(127): Magento\Framework\Webapi\Rest\Request->getRequestData() #5 /var/www/nomo/vendor/magento/module-webapi/Controller/Rest.php(257): Magento\Framework\Webapi\Rest\Request\Proxy->getRequestData() #6 /var/www/nomo/vendor/magento/module-webapi/Controller/Rest.php(160): Magento\Webapi\Controller\Rest->processApiRequest() #7 /var/www/nomo/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http)) #8 /var/www/nomo/vendor/magento/framework/App/Http.php(115): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http)) #9 /var/www/nomo/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch() #10 /var/www/nomo/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http)) #11 {main}"
"trace": null
}

Does somebody know what is going wrong ?

2
  • Hello, Did you found any solution for above issue ? May 14, 2018 at 5:45
  • I got this error after custom parameter did anyone got solution for it Aug 19, 2019 at 11:27

4 Answers 4

4

Body should be in json format, like

{"username":"admin", "password":"123123q"}

example

POST /rest/V1/integration/admin/token HTTP/1.1 
Host: mage.dev 
Content-Type: application/json 
Accept: application/json 
Cache-Control: no-cache 

{"username":"admin", "password":"123123q"}
2

Just make sure your JSON input parameter is valid by using JSON validating tool

https://jsonlint.com/

For example the following JSON is not a valid one which will throw decoding error:

{ "payment" : { "cc_holder_name": "MY NAME", "cc_card_no": "4000000000006", } }

1

Change username='test'&password='test' to json format {"username":"test", "password":"test"}.

If json format doesn't work, change it to JSON.stringify({"username":"test", "password":"test"}), this way worked for me.

0

Make sure you are using UTF-8 encoding. For me, this solved the issue when I was sending a POST request to create/update a product via the REST API.

Your Answer

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

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