简体   繁体   中英

Using Magento REST API

I've searched all over (including here on Stackoverflow) for how to use the Magento REST API. I need help on getting an Unauthorized Request Token (the first step)

On the Magento setup I'm using the REST API is working for GET Products for Guests so I know that is not [the problem][1]

I have setup an OAuth Consumer for the above URL and have both the consumer key and secret. I can't figure out what URL to use for the Callback URL.

First, I'm stuck and don't know what I should use as the Callback URL when setting up the consumer. It is an optional field in Magento

I'm testing with the Firefox REST Client as per http://www.magentocommerce.com/api/rest/testing_rest_resources.html

Next with the Firefox REST client I can't get started by getting an Unauthorized Request Token. According the above URL I should have the oauth_callback URI in the header.

The following request parameters should be present in the Authorization header:

oauth_callback - an URI to which the Service Provider will redirect the resource owner (user) after the authorization is complete. oauth_consumer_key - the Consumer Key value, retrieved after the registration of the application. oauth_nonce - a random value, uniquely generated by the application. oauth_signature_method - name of the signature method used to sign the request. Can have one of the following values: HMAC-SHA1, RSA-SHA1, and PLAINTEXT. oauth_signature - a generated value (signature). oauth_timestamp - a positive integer, expressed in the number of seconds since January 1, 1970 00:00:00 GMT. oauth_version - OAuth version.

What is the oauth_callback URI when using the above URL?

When I try a POST to Endpoint: /oauth/initiate

I get:

oauth_problem=parameter_absent&oauth_parameters_absent=oauth_callback

I'm lost and don't know what else to try. I'm a novice programmer and new to the Magento REST API...so keep that mind. It may be that I'm just missing the obvious.
Anyone who is interested in helping me figure this out here are the Consumer key and the secret.

key: d2f4a7cc63715f98d12db2c6db63cfba

secrect: 8347474102cbf2d40b06f9d76f281e73

The URL is: http://temp.pramier.com

This is from a test install so I'm not worried about giving out the key and secrect

Pass the oauth_callback like http://temp.pramier.com/admin . You is in this step:

Getting an Unauthorized Request Token


The first step to authenticate the user is to retrieve a Request Token from Magento. This is a temporary token that will be exchanged for the Access Token.

Endpoint: /oauth/initiate

Description: The first step of authentication. Allows you to obtain the Request Token used for the rest of the authentication process.

Method: POST

Returns: Request Token

Sample Response: oauth_token=4cqw0r7vo0s5goyyqnjb72sqj3vxwr0h&oauth_token_secret=rig3x3j5a9z5j6d4ubjwyf9f1l21itrr&oauth_callback_confirmed=true


You should continue to get the token. This is the best (and official) tutorial: http://devdocs.magento.com/guides/m1x/api/rest/authentication/oauth_authentication.html#OAuthAuthentication-UsingOAuth

I am not sure what programming language you are using, but the API lists the code for authenticating and retrieving products in php on the bottom.

I just started working on this in ruby using the code here .

@consumer=OAuth::Consumer.new auth["consumer_key"], 
                          auth["consumer_secret"], 
                          {:site=>"your-site-here"}

@request_token = @consumer.get_request_token

Let me know if I misunderstood your question or wasn't clear in my explanation.

Please follow those instructions here:

http://inchoo.net/magento/configure-magento-rest-and-oauth-settings/

After that, follow these steps:

http://www.aschroder.com/2012/04/introduction-to-the-magento-rest-apis-with-oauth-in-version-1-7/

At the beginning of the article, the writer asks to use a Ruby program called oAuth. If you are using Linux, put these commands into the command line to install Ruby and oAuth:

sudo apt-get install ruby

and

sudo gem install oauth

Beware, if you put exactly this:

--authorize-url http://www.yourstore.com/magento/oauth/authorize \\

You'll get a permissions error when you'll want to login. You should replace this by:

--authorize-url http://www.yourstore.com/magento/admin/oauth_authorize \

Everything should go smoothly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM