Magento – Getting started with Magento REST API

apice-1.8.1.0magento-1.8oauthrest

So the official documentation is very terse (bad!), particularly for someone who hasn't worked with REST/Oauth in the past. I'm using Magento 1.8.1 CE.

Can somebody provide a simple PHP example of how to use Magento's REST API?

Using their example code (http://www.magentocommerce.com/api/rest/introduction.html) I get two errors:

Message: Undefined index: state
Message: Use of undefined constant OAUTH_AUTH_TYPE_URI - assumed 'OAUTH_AUTH_TYPE_URI'

Thus far I've done:

  • Install php oauth extension
  • Create at least one product in Magento
  • Configure resource permissions for Admin REST user for retrieving all product data for Admin
  • Create a Consumer

Any help is greatly appreciated.

EDIT: I narrowed down the problem to (surprise, surprise!) OAuth not working properly. I gave up and changed the Guest roles and attributes to allow all. Then, I tested things to see if they were working by navigating to:

http://yourdomain/api/rest/products
http://yourdomain/api/rest/products/1/images

Everything is indeed working. If/when I figure out how to properly deal with authentication, I'll post the answer.

Best Answer

So @user2636834 did you figure this one out already?

I remember when I was setting up a test scenario that I got the sames error(s). Seemed that I didn't have Oauth installed :O. So in short I did (running Ubuntu and following these instructions, also running into this error):

pecl install oauth

Then add extension=oauth.so to php.ini's "Dynamic Extensions" section. Then restart Apache

I tried the examples from the Magento site and got an error from the API:

"Invalid auth/bad request"

I had to add a 'Accept' => '*/*' header to the $oauthClient->fetch() call. After that it worked all just fine.

Hope you can get things running if you hadn't already.

Related Topic