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.
-
You can use the examples listed in here for authentication. magentocommerce.com/api/rest/…. (scroll down until you see code) There is one for guest/customer and one for admin login. They are basically the same, only the url called is different. They worked nicely for me.Marius– Marius2014年06月30日 06:50:13 +00:00Commented Jun 30, 2014 at 6:50
-
I'll have a look. I have guest working now, so I'm messing up authentication. Thanks for the tip. Also, did you have to create a oauth_admin.php file yourself? (sorry if this is explained in the linked article, but I figured I'd ask you since you have it working (:-).user2636834– user26368342014年06月30日 06:53:05 +00:00Commented Jun 30, 2014 at 6:53
1 Answer 1
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.
-
I posted a similar problem here--> magento.stackexchange.com/questions/63611/…. I tried adding
'Accept' => '*/*'to$oauthClient->fetch()and still get a403 Forbiddenresponse. Someone else said they solved the 403 after installing SSL. Is that really necessary? (just to be clear, I have Oauth installed and I'm only getting a 403 error - no other errors)gtr1971– gtr19712015年04月15日 12:57:32 +00:00Commented Apr 15, 2015 at 12:57
Explore related questions
See similar questions with these tags.