WooCommerce-REST-API-Client-Library icon indicating copy to clipboard operation
WooCommerce-REST-API-Client-Library copied to clipboard

Implement WooCommerce REST API into Android app (POST Method)

Open pkhutal opened this issue 9 years ago • 38 comments

Hello, I am developing Android Application and using woocommerce REST API i am able to fetch products and display them in android app (with all procedure of signing and authnentication).

But i am not able to create order and customer using POST method in android. I have gone through documentation and all available things but not found something related to POST method in android.

I am getting "404 error". while creating customer order.

Also In PHP i am able to create orders etc ,but same i am not able to achieve in android or in java code.

Please help me to deal with this.

Thank You...

pkhutal avatar Feb 23 '16 08:02 pkhutal

can you please share with us that how have you implemented wc in android.

milon87 avatar Mar 07 '16 15:03 milon87

Thanks for your response....actually now everything is working fine....there was problem with headers in POST method.:)

pkhutal avatar Mar 07 '16 16:03 pkhutal

I am trying to fetch product in json format using rest over http and display them in android. But getting confused how to authentication (authentication and signing procedure). can you please help me to implement authentication and signing to fetch product in json format response. Here is my email add: [email protected] Thanks.

milon87 avatar Mar 09 '16 02:03 milon87

can you please share how you implemented WC in android my mail id is [email protected]

kaushalkishore1 avatar May 24 '16 02:05 kaushalkishore1

can you please share how you implemented WC in android my mail id is [email protected]

Man-Fai avatar Jun 14 '16 04:06 Man-Fai

can you please share how you implemented WC in android my mail id is [email protected]

Ang3lC3rvant3s avatar Jun 16 '16 19:06 Ang3lC3rvant3s

Hi pkhutal, could you please post here your code for implementing WC in android? or maybe you could send it to me, my email is [email protected]. I would appreciate it.

jafethdc avatar Jun 27 '16 15:06 jafethdc

Hi, May I take at look at your code for implementing woocommerce? you can send it in my email [email protected]. Thank you

teza8392 avatar Jul 19 '16 23:07 teza8392

Could you please tell me how you did it i am trying to build android app for my woocommerce website but have no ideas...please help It would be great if you could send me a code snippet or a demo project email: [email protected]

Thank You

princiee avatar Aug 11 '16 07:08 princiee

i have problem to fetch data in woocommerce ...i think i cant sign to it.plz help to me [email protected] tnx a lot

mostafaolyai avatar Sep 26 '16 13:09 mostafaolyai

I have also issue with customer create api of woocommerce in post method in android.Could you please help me. email: [email protected]

Thank you

ranjith068 avatar Sep 27 '16 09:09 ranjith068

I am trying to fetch product in json format using rest over http and display them in android. But getting confused how to authentication (authentication and signing procedure). can you please help me to implement authentication and signing to fetch product in json format response. my email add: [email protected] Thanks.

kshirsagardeepak avatar Nov 07 '16 07:11 kshirsagardeepak

yes!! this is very simple @kshirsagardeepak @DevSmoo @milon87 you can refer my problem https://github.com/woocommerce/wc-api-php/issues/65 setting up the library & accessing APIs

and also https://github.com/woocommerce/wc-api-php/issues/67 getting JSON output from localhost or anywhere

all you have to do is .. 1st download COMPOSER may be familier with Laravel installation ok download it . 2nd download wc Rest api Client library rest api unzip it and place it to( htdocs at XAMPP folder) 3rd after installation type 'composer require automattic/woocommerce' in CMD of requested folder with admin privillages.... in my case i.e. htdocs 4th now you will able to see VENDORS folder in htdocs and also comoposer.json or .lock now you have to create an index.php file and paste that code you will find on my problem

'require __DIR__ . '/vendor/autoload.php';

use Automattic\WooCommerce\Client;

$woocommerce = new Client(
    'http://example.com', 
    'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 
    'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    [
        'wp_api' => true,
        'version' => 'wc/v1',
    ]
);'

`try {
// Array of response results.
$results = $woocommerce->get('products');
// Example: ['products' => [[ 'id' => 8, 'created_at' => '2015-05-06T17:43:51Z', 'email' => ...

$json_string = json_encode($results, JSON_PRETTY_PRINT);
\print_r($json_string);
}
`

fire XAMPP localhost you will be able to use your API and JSON output in app or anywhere. good luck with.lv.incals

Lavkushwaha avatar Dec 02 '16 13:12 Lavkushwaha

https://github.com/woocommerce/wc-api-php/issues/65

Lavkushwaha avatar Dec 02 '16 13:12 Lavkushwaha

https://github.com/woocommerce/wc-api-php/issues/67

Lavkushwaha avatar Dec 02 '16 13:12 Lavkushwaha

can you please tell me how you have implemented wc in android its with Volley request or some other third party library. My email id is [email protected]

Mamtakaundal avatar Jan 18 '17 10:01 Mamtakaundal

I also need an example for android App using rest API of a woo commerce website for getting products and their info. All other info also. Please help me get this asap, my mail id: [email protected]

If any one have solution please help me to solve this problem.

harshmittal2810 avatar Mar 15 '17 16:03 harshmittal2810

Can you please share how you implemented WC Rest API in Android. My email is [email protected]

maheshbohara avatar Mar 27 '17 05:03 maheshbohara

Could you please tell me how you did it i am trying to build android app for my woocommerce website but have no ideas...please help It would be great if you could send me a code snippet or a demo project email: [email protected]

Thank You

tarangn avatar Apr 05 '17 12:04 tarangn

Sorry guys but your savior has come :) Jokes aside I have managed to create resources(specifically coupon and order at this point of time) using java in android after toiling for 2 days. Please check this stackoverflow link and thumbs up and also comment if any doubts.

http://stackoverflow.com/questions/43348471/android-cant-create-order-using-woocommerce-api/43407073#43407073

debChowdhury avatar Apr 14 '17 07:04 debChowdhury

Could you please tell me how you did it i am trying to build android app for my woocommerce website but have no ideas...please help It would be great if you could send me a code snippet or a demo project email: [email protected]

Thank You

SumitDesai avatar May 15 '17 18:05 SumitDesai

Please check the stackoverflow link.The link is given in my github comment.Also like and accept the answer and if any doubt persists please comment. Thanks.

On Mon, May 15, 2017 at 11:31 PM, SumitDesai [email protected] wrote:

Could you please tell me how you did it i am trying to build android app for my woocommerce website but have no ideas...please help It would be great if you could send me a code snippet or a demo project email: [email protected]

Thank You

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kloon/WooCommerce-REST-API-Client-Library/issues/162#issuecomment-301555224, or mute the thread https://github.com/notifications/unsubscribe-auth/APgx51xDHBEefGao4xymRhlPXEDPVerOks5r6JMNgaJpZM4HgXzn .

debChowdhury avatar May 16 '17 02:05 debChowdhury

Hi,

Can you please send me the java code to create a oauth signature.

Thanks and Regards, Sumit Desai

On Tue, May 16, 2017 at 8:24 AM, debu-Chow [email protected] wrote:

Please check the stackoverflow link.The link is given in my github comment.Also like and accept the answer and if any doubt persists please comment. Thanks.

On Mon, May 15, 2017 at 11:31 PM, SumitDesai [email protected] wrote:

Could you please tell me how you did it i am trying to build android app for my woocommerce website but have no ideas...please help It would be great if you could send me a code snippet or a demo project email: [email protected]

Thank You

— You are receiving this because you commented. Reply to this email directly, view it on GitHub <https://github.com/kloon/WooCommerce-REST-API-Client- Library/issues/162#issuecomment-301555224>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ APgx51xDHBEefGao4xymRhlPXEDPVerOks5r6JMNgaJpZM4HgXzn> .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kloon/WooCommerce-REST-API-Client-Library/issues/162#issuecomment-301661230, or mute the thread https://github.com/notifications/unsubscribe-auth/AFFyylme7xidWKXaunfMdhP7agk4EH4zks5r6Q_ggaJpZM4HgXzn .

SumitDesai avatar May 16 '17 08:05 SumitDesai

Hi,

Just try for folling sample: https://github.com/rajatady/Woocommerce-Android-Client might this be helpful.

and get api related help by: https://woocommerce.github.io/woocommerce-rest-api-docs/

k2infoworldz avatar May 16 '17 08:05 k2infoworldz

Ok I am sending you my code for generating signature in android java.If any doubt please comment.And also if you like,you can upvote my stackoverflow answer so that it can be visible to others as well.(Also will get the "put bounty feature" :)).

client = new InitializeBuilderOkhttp().returnInitializeBuilderOkhttp(); oauthConsumerSecretKeyStringValue = "cs_0b5389fff3d301....ddbdb325fbd64cdc8f4"; oauthConsumerKeyString = "oauth_consumer_key"; oauthConsumerKeyStringValue = "ck_2f53925cb6d2c8f96407.....5f118d01ed80e"; oauthTimestampKeyString = "oauth_timestamp"; oauthTimeStampKeyStringValue = ""; oauthNonceKeyString = "oauth_nonce"; oauthNonceKeyValue = ""; oauthSignatureMethodKey = "oauth_signature_method"; oauthSignatureMethodKeyValue = "HMAC-SHA1"; pageKeyString = "page"; pageKeyValue = getPage; parameterString = ""; urlOrders = "your url.In this case the coupon url."; urlOrdersEncoded = URLEncoder.encode(urlOrders,"utf-8"); Long tsLong = System.currentTimeMillis()/1000; String ts = tsLong.toString(); oauthTimeStampKeyStringValue = ts; oauthNonceKeyValue = randomGenerate();//this is a method to produce a random string of 6 characters.See below. parameterString = URLEncoder.encode(oauthConsumerKeyString,"utf-8")+"="+URLEncoder.encode(oauthConsumerKeyStringValue,"utf-8"); parameterString = parameterString+"&"+URLEncoder.encode(oauthNonceKeyString,"utf-8")+"="+URLEncoder.encode(oauthNonceKeyValue,"utf-8"); parameterString = parameterString+"&"+URLEncoder.encode(oauthSignatureMethodKey,"utf-8")+"="+URLEncoder.encode(oauthSignatureMethodKeyValue,"utf-8"); parameterString = parameterString+"&"+URLEncoder.encode(oauthTimestampKeyString,"utf-8")+"="+URLEncoder.encode(oauthTimeStampKeyStringValue,"utf-8");

parameterStringEncoded = URLEncoder.encode(parameterString,"utf-8"); parameterStringBeforeEncoding = "?"+oauthConsumerKeyString+"="+oauthConsumerKeyStringValue; parameterStringBeforeEncoding = parameterStringBeforeEncoding+"&"+oauthTimestampKeyString+"="+oauthTimeStampKeyStringValue; parameterStringBeforeEncoding = parameterStringBeforeEncoding+"&"+oauthNonceKeyString+"="+oauthNonceKeyValue; parameterStringBeforeEncoding = parameterStringBeforeEncoding+"&"+oauthSignatureMethodKey+"="+oauthSignatureMethodKeyValue;

signatureBaseString = "POST&"+urlOrdersEncoded+"&"+parameterStringEncoded;

Please check the order of the url formed carefully.This is the order to be followed.

Mac mac = null; mac = Mac.getInstance("HMAC-SHA1"); String secret = oauthConsumerSecretKeyStringValue+"&"; mac.init(new SecretKeySpec(secret.getBytes("utf-8"), "HMAC-SHA1")); signature = Base64.encodeToString(mac.doFinal(signatureBaseString.getBytes("utf-8")), 0).trim(); MediaType JSON = MediaType.parse("application/json; charset=utf-8"); JSONObject totalJsonObject = new JSONObject(); JSONObject dataJsonObject = new JSONObject(); dataJsonObject.put("code","asdfas"); totalJsonObject.put("data",dataJsonObject); Log.d("url",""+urlOrders+parameterStringBeforeEncoding+"&oauth_signature="+signature); Log.d("json",""+dataJsonObject.toString()); okhttp3.RequestBody body = RequestBody.create(JSON, postDataString); okhttp3.Request request = new okhttp3.Request.Builder() .url(urlOrders+parameterStringBeforeEncoding+"&oauth_signature="+signature) .post(body) .build();

public static String randomGenerate() { final String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; final int N = alphabet.length();

Random r = new Random();
String outputRandom = "";

for (int i = 0; i < 6; i++) {
    outputRandom = outputRandom+alphabet.charAt(r.nextInt(N));
}
return outputRandom;

}

On Tue, May 16, 2017 at 2:11 PM, cool kk [email protected] wrote:

Hi,

Just try for folling sample: https://github.com/rajatady/Woocommerce-Android-Client might this be helpful.

and get api related help by: https://woocommerce.github.io/woocommerce-rest-api-docs/

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kloon/WooCommerce-REST-API-Client-Library/issues/162#issuecomment-301715259, or mute the thread https://github.com/notifications/unsubscribe-auth/APgx58HKWhBEDAC6ahnheBOodq8SKv_Wks5r6WEngaJpZM4HgXzn .

debChowdhury avatar May 16 '17 15:05 debChowdhury

I have also issue with customer create api of woocommerce in post method in android.Could you please help me. email: [email protected]

Thank you

RaviDhakad avatar Jun 21 '17 04:06 RaviDhakad

@pkhutal I too have issues with android post methods in c.Please forward the code or library used in android.

Thanks in advance

iamvamshi avatar Aug 10 '17 05:08 iamvamshi

@pkhutal Hi, I am also trying to connect woocommerce with android but I am getting so confused with the oauth process could you please email me how you did it please? My email is [email protected] Kind regards

TedMayombo avatar Oct 19 '17 18:10 TedMayombo

hi all can someone send me his android code that can get anything (product list or categorie list ) from WC api here is my email: [email protected]

Thanks in advance

ninoxdzd avatar Feb 06 '18 10:02 ninoxdzd

Hello @pkhutal

Can you please share how you implemented WC in android my mail id [email protected]

Thanks

sahilpatel2216 avatar Apr 28 '18 12:04 sahilpatel2216