How to use POSTMAN rest client with magento REST a

2019-01-13 01:01发布

I am a beginner to magento REST API, how i will get token and token secret to be fill in Postman REST resquest. I have only consumer key and consumer secret. Please provide me the steps to follow.

3条回答
孤傲高冷的网名
2楼-- · 2019-01-13 01:42

Example request in Postman version 6.x.x

image.png

And response of this request is

image.png

You can get this credentials from Magento Admin. Click on edit icon in Integrations page.

image.png

查看更多
干净又极端
3楼-- · 2019-01-13 01:44

@Franklin P Strube Unfortunately, I don't have enough reputations to add a comment.

I would like to add the following. The Magento REST API does not require both outh params on the URL AND Oauth headers. This is not actually stated above. See the last note where it says you need to "add params to header". You do need to do this, but when you do you will find it sends both url params and oauth headers. You don't need the url parms, it will work fine without them. btw: the franklin response worked great!

查看更多
不美不萌又怎样
4楼-- · 2019-01-13 01:46

First, you want to request a valid OAuth token and secret. Do this by hitting the /oauth/initiate URL of your Magento store with a GET parameter for oauth_callback. We're going to use httpbin so that we can echo anything that is passed to our callback. Make sure you have "Auto add parameters" checked on the OAuth 1.0 settings for Postman.

OAuth Token Request

That will give you an oauth_token and oauth_token_secret, which are only temporary. These are referred to as a "request token" and secret. Save these values somewhere because you will need them later.

OAuth Token Response

Now, assemble a new regular HTTP request to the /admin/oauth_authorize URL of your Magento store. This will return a login form where you can accept the oauth token and authorize your app, however since we're using Postman we aren't able to interact with the form.

OAuth Authorization Form

Instead, view the source and pull out the form_key hidden input value. Then assemble a new HTTP request to fake the submission of the authorization form. Make sure it is a POST request. Your new HTTP request should look like this.

OAuth Authorization Form Submit

Now, you need to actually confirm the authorization. Simply issue a GET to the /admin/oauth_authorize/confirm URL of your Magento store with the oauth_token as your parameter. When you send this request it will redirect to your oauth_callback from the first step. Now, you can see why we used httpbin as our callback in the first step.

OAuth Authorization Confirmation

OK. So, we're almost home. The last piece of the puzzle is to use the oauth_token, oauth_secret, and oauth_verifier all together to get a valid and persistent "access token". So, take the oauth_token_secret from the first step, and combine and assemble a new OAuth request like so.

OAuth Token

You should get a returned token and secret. These will never expire! You can use them to query products and stuff.

OAuth Token Response

Now, you can assemble your OAuth requests like this. Edit: Note, you must check the "Add params to header" checkbox in order for Magento REST calls to work properly.

OAuth REST Request

查看更多
登录 后发表回答