2

Trying to integrate magento 2.0 with a desktop application (i.e the desktop application should be able to create products & download orders) using the REST API.

I am trying to make a 'POST' call to Magento 2.0 token request to get the access token, however, I am getting an error while sending the request:

oauth_problem=Consumer+key+has+expired.

I am trying to generate the signature using:

POST http://xxxxxx/magento/oauth/token/request?oauth_nonce=cyzHawrmnCYz7cJT&oauth_signature_method=HMAC-SHA1&oauth_time

I have been trying to implement rest API. may be, can I try SOAP if rest API did not work out. really confusing which is advisable to use? REST or SOAP based I am using bitnami Magento 2.1.6. bitnami is like a library which takes over of wamp,Magento installation as a package. is that okay to use or separation installation is best?

Help needed.

Rafael Corrêa Gomes
13.9k15 gold badges92 silver badges190 bronze badges
asked Sep 29, 2016 at 15:22

3 Answers 3

2

Try to recheck the official documentation step by step :

Token based with Magento admin user/pass: http://devdocs.magento.com/guides/v2.0/get-started/authentication/gs-authentication-token.html

For OAUTH : http://devdocs.magento.com/guides/v2.0/get-started/authentication/gs-authentication-oauth.html

You can test it on a local environment to be sure bitnami is not the root cause.

Thanks,

answered Sep 30, 2016 at 9:41
2
  • Are there any resources that give a full explanation of the process with examples? The documentation from Magento is somewhat lacking in "how-to", it's more like basic concept description than any actionable steps. Most other sites I've found just regurgitate the same Magento doc pages you linked with no actual added info. Is there anything more descriptive for those of us who may need a little bit more hand holding? Commented Oct 12, 2016 at 17:14
  • The easiest way : 1/ Create an Admin user with correct permission 2/ Make a POST request in order to retrieve admin token : curl -X POST "magento.host/index.php/rest/V1/integration/admin" \ -H "Content-Type:application/json" \ -d '{"username":"adminuser", "password":"adminpassword"}' 3/ Use the access token retrieved in the last request in order to use API calls : curl -X GET "magento.ll/index.php/rest/V1/customers/2" -H "Authorization: Bearer vbnf3hjklp5iuytre". You can use SOAP UI in order to test Magento 2 API without CURL Commented Oct 13, 2016 at 15:32
2

These steps below show how to use an admin user to get an API authentication and how to use it.

But you can find all APIs URLs accessing this URL on your store:

www.yourstore.com.br/swagger/

To see all administrator methods (not only the guest methods), you can paste the api_key on the top right of the page and click to apply, this api_key is the key returned in step 1 below.

Step-by-Step

1 - Get your authentication token if this command, the token no expiry it just can be invalidated. Change the ADMIN_USER and PASSWORD_USER to yours.

curl -X POST \
 http://yourstore.com/rest/default/V1/integration/admin/token \
 -H 'cache-control: no-cache' \
 -H 'content-type: application/json' \
 -d '{
 "username": "ADMIN_USER",
 "password": "PASSWORD_USER"
}'

2 - To check your connection you can get the list of the installed modules using this command below. You must change the XXXXXX_TOKEN_HERE_XXXX to use your token returned in step 1.

curl -X GET \
 http://yourstore.com/index.php/rest/V1/modules \
 -H 'authorization: Bearer XXXXXX_TOKEN_HERE_XXXX' \
 -H 'cache-control: no-cache' \
 -d '{
 "searchCriteria": {
 "currentPage": 0
 }
}'
answered May 10, 2017 at 20:23
0

I simply execute this snippet in dev console on the frontend

jQuery.ajax({
 url: "/rest/V1/integration/admin/token",
 type: "POST",
 data: JSON.stringify({"username": "_your_user_name","password": "_your_password"}),
 contentType: 'application/json',
 success: function (html, status, response) {
 console.log('success', html);
 }});
answered Oct 24, 2018 at 23:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.