-1

I am trying to build an Android app that connects local users to a WordPress/WooCommerce site and retrive data from it to use them in the app.

How could I autorize app to retreive woocomerce data from my site using postman please?

Any help would be appricaited.

Kamba-Bilola Ted
  • 179
  • 2
  • 12

1 Answers1

3

actually I asked this question because I spent months (and I mean months) trying to figure it out; and I did not get any answer that really helped me, beside this tutsplus.com tutorial which was instrumental in order for me to solve the problem; the WooCommerce REST API doc is so confusing it made things even worst for me but it still worth reading.

First step: Setting plugins and getting necessary information to start

  1. First of all, install and activate “WooCommerce”, "WP REST API" and "WP REST API - OAuth 1.0a Server" plugins on your WoordPress site;
  2. Then, install postman on your computer;
  3. Then go to the API Tab from WooCommerce setting page of the dashboard and make sure the activate REST API check box is ticked;
  4. Still in WoordPress backend, create a new user by clicking the add new button on the users>applications page (this will only show if you have properly installed and activated the plugins mentioned above );

  5. After the user is created; Copy the client key (CK) and the client secret(CS) and saved them somewhere safe;

  6. Then, go back to the users>applications page and hover the edit link under the name of the user you have just created; the user id appears bellow the page (in the left corner of your screen); Write it down to have it at hand.

We finished the first step to collect necessary data to start authenticating the app and establishing the communication between the website and the app.

Second step: Getting the final Token and building the WC authorization URL

This steps consists of using data we collected above to get the final token (not to be confused with temporary token) and build the WooCommerce authorization URL that establishes the communication between the app and the website.

I should only have used postman for this step but since I couldn’t login to my website dashboard from postman for windows, I switched between postman and my browser. I guess the newest version of postman will solve this since they are killing the chrome add on… never mind let go:

  1. In the postman dashboard,in the URL area, paste the following: mysite.com/wp-json. Chose GET as a method and pressed the SEND button; You will get this:

"authentication": {"oauth1": { "request": "mysite.com/oauth1/request",
"authorize": "mysite.com/oauth1/authorize", "access":"mysite.com/oauth1/access","version": "0.1"}

as part of your response. 2. Click the first link (mysite.com/oauth1/request) ; postman opens a new tab; Under TYPE, chose OAuth 1.0 ; new fields appear at the right. Fill in the client key (CK) and the client secret (CS) we got from the step above respectively in the Consumer Key and Consumer Secret fields; then, click the SEND button again. The response you will get is something like this:

oauth_token=your_oauth_token_is_here&oauth_token_secret=your_oauth_token_secret_is_here&oauth_callback_confirmed=true

  1. Copy the value of your oauth_token (TK) and your oauth_token_secret( TKS ); but remember this are only temporary values not to be confused with the final oauth_token and the final token secret;
  2. Go back to your very first tab in postman and click the second link from the response (mysite.com/oauth1/authorize) ; postman opens a new tab; Under TYPE chose OAuth 1.0 ; new fields appear at the right. Fill in your temporary oauth_token (TK) and your temporary oauth_token_secret( TKS ). Click send. In the response section click the Preview link to see what the response looks like and it will ask to login as a WoordPress user which you can’t from postman;
  3. So scroll to the top of postman and clicke on the code link under the Save button; Select JAVA OK HTTP as the language; You will get this kind of code:

mysite.com/oauth1/authorize?oauth_consumer_key=your_costumer_key_is_here&oauth_token=your_temporary_token_key_is_here&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1512645061&oauth_nonce=VHeUrwCl4CP&oauth_version=1.0&oauth_signature=3bMUiF8%2Fg57EkwaDOdnQ8m3s8TQ%3D

Copy the URL in the parenthesis and paste it in your browser where you are already logged in as a WoordPress user;

  1. Give the app authorization; it will redirect you to a page with your verification Token (VT) which you have to copy and keep somewhere.
  2. Go back to your very first tab in postman and clicked the third link from the response (mysite.com/oauth1/access) ; postman opens a new tab; Chose OAuth 1.0 as a type ; new fields appear at the right. Before the SEND button there is a Params button; click it ;new fields appears; Enter oauth_verifier as a key and your verification Token (VT) as value; then press SEND; the response looks like this:

oauth_token=your_final_token_is_here&oauth_token_secret=your_final_token_secrete_is_here

These are your final oauth_token (FTK) and your final oauth_token_secret( FTKS ); 8. Now we can build our final URL; Open a new tab in postman ; In the URL section , paste (mysite.com/wc-auth/v1/authorize ) ; select OAuth 1.0 as a type; fields appear at the right. Replace the Access Token value with your final oauth_token (FTK) and the Token Secret with final oauth_token_secret( FTKS); 9. Click on the Params button and enter the following as pairs of key/value:

app_name => your_app_name (from step 1); user_id => your_user_id (from step 1) return_url=> your_return_url (I used mysite.com) callback_url=> your_callbak_url (I used mysite.com)

Click the SEND button; once your response is 200 OK; click on the code link to view the corresponding JAVA OK HTTP code ; copy the URL and past it in your browser and only then you could see the app asking for approval to access WooCommerce data; I mean this: enter image description here

So all you need to do now is to copy the entire OKHTTP code generated from postman and use it in your ANDROID java app to get permission; I used webview to display this response page in my app . I hope that will help lots of people struggling with this problem.

Kamba-Bilola Ted
  • 179
  • 2
  • 12