2

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 ?

  • Hello, Did you found any solution for above issue ? – Aditya Shah May 14 '18 at 5:45
2

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"}
1

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", } }

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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