Magento 1.9 – Fix Invalid Auth/Bad Request in Rest API

apimagento-1.9rest

I followed http://devdocs.magento.com/guides/m1x/api/rest/authentication/oauth_configuration.html

I am able to login to "My first application" with admin.

But not with customer.

I got $_SESSION like

Array
(
    [secret] => 7664a04e54256c135a18b313a9d06872
    [state] => 2
    [token] => fc5be1e6d0cd1cde0ed614281b61894f
)

I got error in this line

$oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json'));

Saying that

Invalid auth/bad request (got a 500, expected HTTP/1.1 20X or a redirect)

Service temporary unavailable

Please help me solve this.

Best Answer

It seems you should to add "'Accept' => 'application/json'" or 'Accept' => /. So

$oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json'));

should to be

$oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json', 'Accept' => 'application/json'));

or

$oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json', 'Accept' => */*));