Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento REST api

I am trying to use magento rest api for customers. But when i authenticate the application, it gives me following error.

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

I am trying to fetch product collection for customer role.

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

The line of code throws exception.

Any help will be appreciated.

like image 897
Hasina Avatar asked May 23 '14 05:05

Hasina


People also ask

What is Magento REST API?

The Magento REST API defines a set of functions that a developer can use to perform requests and receive responses. These interactions are performed using the HTTP protocol. The caller issues an HTTP request, which contains the following elements: An HTTP header that provides authentication and other instructions.

What framework does Magento 2 use for its REST API?

Magento uses Swagger to display REST APIs for all installed products and allows you to try out the APIs.

Does Magento have an API?

The Magento web API framework provides integrators and developers the means to use web services that communicate with the Magento system. Key features include: Support for GraphQL, REST (Representational State Transfer) and SOAP (Simple Object Access Protocol).


2 Answers

Have you tried adding an "Accept" header to your request? I ran into the same problem with the Magento API, tested it and found that the PHP OAuth client doesn't send any accept header by default. So try the following instead:

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

or

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

You can view more info about the exception by using the following when you set up the client:

$oauthClient->enableDebug();

...and then looking at the debug with:

$oauthClient->debugInfo

or

$oauthClient->getLastResponse

The other methods are documented here:

http://www.php.net/manual/en/class.oauth.php

like image 142
Sam Critchley Avatar answered Sep 22 '22 03:09

Sam Critchley


I've used $oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json', 'Accept' => '*/*')); which works fine.

like image 25
amitshree Avatar answered Sep 22 '22 03:09

amitshree