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 ?

asked May 2, 2016 at 7:29
2
  • Hello, Did you found any solution for above issue ? Commented May 14, 2018 at 5:45
  • I got this error after custom parameter did anyone got solution for it Commented 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"}
answered May 2, 2016 at 10:48
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.

answered Dec 11, 2017 at 8:23
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", } }

answered Sep 25, 2018 at 8:48
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.

answered Nov 21, 2019 at 8:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.