cancel
Showing results for 
Search instead for 
Did you mean: 

Server can not understand Content-Type HTTP header media type "application/x-www-form-urlencoded

Highlighted

Server can not understand Content-Type HTTP header media type "application/x-www-form-urlencoded

I am a Ruby on Rails developer. I am trying to integrate Magento rest api in my application.

 

I have generated AccessToken and OauthTokenSecret successfully using ConsumerKey and ConsumerSecret ( via oauth authentication ).

 

After doing all this I am able to send GET requests successfully to access orders, products, stock-items etc.

 

But i am getting following error on sending PUT request to update "StockItems" for a product:

"{\"messages\":{\"error\":[{\"code\":400,\"message\":\"Server can not understand Content-Type HTTP header media type \\\"application\\/x-www-form-urlencoded\\\"\"}]}}"

 

Following is the request i am sending:

Request: PUT "http://www.groovepacker.com/store/api/rest/stockitems/3"

Parameters: "qty=999"

Note: Also provided Authorization header for oauth authentication

 

It seems like PUT string is not encoded properly. Can anyone please suggest me the right way to overcome this issue.

 

Thanks in advance.

4 REPLIES 4
Highlighted

Re: Server can not understand Content-Type HTTP header media type "application/x-www-form-urlen

Hello,

 

I am facing the same problem when trying to call a Magento api in Laravel.

 

Did you found a solution for your problem?

 

Regards.

Highlighted

Re: Server can not understand Content-Type HTTP header media type "application/x-www-form-urlen

Hello, I am facing the same problem when trying to call a Magento api in Laravel. Did you found a solution for your problem? Regards.
Highlighted

Re: Server can not understand Content-Type HTTP header media type "application/x-www-form-urlen

I think you have to add another header to your request to declare the right content-type:

Content-Type:application/json
Highlighted

Re: Server can not understand Content-Type HTTP header media type "application/x-www-form-urlen

It clearly says a problem with urlencode. Magento 2 will not allow you to use urlencoded strings. Make sure all your input values are json encoded and you are mentioning the content type as well.