13

i am planning to develop a native mobile Android App for WooCommerce shops.

I had a look at their REST API documentation here: http://docs.woocommercev2.apiary.io/ I already started to test it but when i do different calls

GET /orders let's say it returns all the orders of the shop.

Does anyone have any idea how can i develop a enduser app using their API.

for example:

GET /products

PUT /order (create a order for the logged in User)

GET /order (get orders of the logged in User)

Any idea is appreciated :)

Thanks in advance.

Agli Panci
  • 494
  • 1
  • 9
  • 21
  • U got any solutions? – Dilip Rajkumar Aug 15 '15 at 07:38
  • 1
    @DilipRajkumar the only solution is to write it all by yourself by using woocommerce hooks when you can, i didn't found any other solution :/ – Agli Panci Aug 20 '15 at 10:01
  • Hay I found the answer using oAuth.. I will update as soon as I go home.. not all the functionality.. however we can get most of then we need. – Dilip Rajkumar Aug 20 '15 at 10:28
  • user1305626: Did you make android app using REST API? I am getting Signature issue in Android app. Can you let me know how to generate Signature for WooCommerce REST API? Here is my question: http://stackoverflow.com/questions/32948988/invalid-signature-provided-signature-does-not-match-woocommerce-rest-api-calli – Ramesh Kumar Oct 06 '15 at 07:51
  • @DilipRajkumar please send me solution too.. – Maha Dev Oct 07 '15 at 08:56
  • Enable API in backend -> Using lighweight middleware -> Connect server -> Return JSON data to your app. Otherwise try readily built api in apphitect http://www.apphitect.ae/mobile-commerce-app.php – Sivakumar Jun 30 '16 at 13:51

4 Answers4

2

I would suggest this steps

First thing you can Enable Api for woocommerce from the backend – http://docs.woothemes.com/document/woocommerce-rest-api/

https://www.npmjs.com/package/woocommerce use this link, which has all the methods to interacting with woocommerce. Otherwise using lightweight middleware, it help to connect woocommerce server & return JSON data to your app.

Write a service using ionic framework and talk to your thin middleware client. Do not forget to cache the data (using local storage), so that you don’t hit the server all the time. - Contus M Comm

user93884
  • 69
  • 4
2

For http (and not ssl protocol such as https ) request, you must use from OAthu 1.0a authenticate framework. There are many libraries for oauth 1.0a in java, i'm use from scribeJava

So, do the following steps:

  1. In app/build.gradle in dependency scop add this:

    compile 'org.scribe:scribe:1.3.5'

  2. New class as WoocommerceApi for provider of OAuth service. important. You must use a
    public class in DefaultApi10a for implementing oauth provider

    public static class WooCommerceApi extends org.scribe.builder.api.DefaultApi10a {
    
        @Override
        public org.scribe.model.Verb getRequestTokenVerb()
        {
            return org.scribe.model.Verb.POST;
        }
    
        @Override
        public String getRequestTokenEndpoint() {
            return "http://www.your-domain.com/wc-auth/authorize";
        }
    
        @Override
        public String getAccessTokenEndpoint() {
            return "none";
        }
    
        @Override
        public String getAuthorizationUrl(org.scribe.model.Token requestToken) {
            return "none";
        }
    }
    
  3. And you Must make request in Thread or AsyncTask

    String restURL = "http://www.your-domain.com/wp-json/wc/v1/products/";
    OAuthService service = new ServiceBuilder()
         .provider(WooCommerceApi.class)
         .apiKey(CONSUMER_KEY) //Your Consumer key
         .apiSecret(CONSUMER_SECRET) //Your Consumer secret
         .scope("API.Public") //fixed
         .signatureType(SignatureType.QueryString)
         .build();
    OAuthRequest request = new OAuthRequest(Verb.GET, restURL);
    // for POST requests 
    // OAuthRequest request = new OAuthRequest(Verb.POST, restURL); 
    // request.addBodyParameter(YOUR_PARAM_KEY, YOUR_VALUE);
    // or 
    // request.addPayload(YOUR_JSON);
    Token accessToken = new Token("", ""); //not required for context.io
    service.signRequest(accessToken, request);
    Response response = request.send();
    Log.d("OAuthTask",response.getBody());
    
ultra.deep
  • 1,699
  • 1
  • 19
  • 23
  • 1
    Your above answer was perfect and to the point. One more thing I need to ask that, You've written the above solution for GET Method only. What should we do if we want to POST and add any parameter? Any help would be appreciated. – Pankaj Lilan Feb 28 '18 at 09:00
  • Hey! can you explain your answer more actually i'm trying to implement woo commerce API but not getting data in my app. Implementing 1.0 authentication – A.Gun Dec 19 '18 at 09:41
  • @PankajLilan I updated my answer... you can use request.addpayload() method – ultra.deep Feb 02 '19 at 10:48
  • It worked for me, thanks. My query is can I do it with retrofit? – Sandeep Singh Jan 28 '20 at 09:47
0

According to the documentation the expected data format is JSON only (in contrast with the previous XML or Json) but there is unfortunately no further explanation on which data structure is expected for each endpoint.

Here's the only example of a POST request format from the current documentation for creating a coupon:

REST request URI

POST http://private-anon-0fe404a22-woocommercev2.apiary-mock.com/coupons?fields=id,code&filter=filter[limit]=100&page=2

Java code (pasted from the documentation)

Client client = ClientBuilder.newClient();
Entity payload = Entity.json("{  'coupon': {    'code': 'autumn-is-coming',    'type': 'fixed_cart',    'amount': '4.00',    'individual_use': true,    'description': ''  }}");
Response response = client.target("http://private-anon-0fe404a22-woocommercev2.apiary-mock.com")
  .path("/coupons{?fields,filter,page}")
  .request(MediaType.APPLICATION_JSON_TYPE)
  .post(payload);

System.out.println("status: " + response.getStatus());
System.out.println("headers: " + response.getHeaders());
System.out.println("body:" + response.readEntity(String.class));

Json response

{
  "coupon": {
    "id": 21548,
    "code": "augustheat",
    "type": "fixed_cart",
    "created_at": "2014-08-30T19:25:48Z",
    "updated_at": "2014-08-30T19:25:48Z",
    "amount": "5.00",
    "individual_use": false,
    "product_ids": [],
    "exclude_product_ids": [],
    "usage_limit": null,
    "usage_limit_per_user": null,
    "limit_usage_to_x_items": 0,
    "usage_count": 0,
    "expiry_date": "2014-08-30T21:22:13Z",
    "apply_before_tax": true,
    "enable_free_shipping": false,
    "product_category_ids": [],
    "exclude_product_category_ids": [],
    "exclude_sale_items": false,
    "minimum_amount": "0.00",
    "maximum_amount": "0.00",
    "customer_emails": [],
    "description": "Beat the August heat with $5 off your purchase!"
  }
}

http://docs.woocommercev2.apiary.io/#reference/coupons/coupons-collection/create-a-coupon

Considering the API is claimed to be accepting POST requests for all relevant endpoints this should be possible with a shopping order.

TNTanuki
  • 59
  • 7
  • It also looks like the documentation is under construction so there might be other examples in the near future. I am also figuring the REST API out and will update my answer if I make any progress. This is more suited as a comment but I cannot comment yet. – TNTanuki Dec 18 '14 at 05:22
  • TNTanuki Thanks for the reply but what i was pointing out was an API for the enduser because this way you have access in every resource of the system. I was thinking for an API that a single user can login and purchase on using his shopping card and his details. – Agli Panci Dec 24 '14 at 08:29
  • Do you mean that you don't want the credential keys to be available on the client side ? If your concern is about being logged in, you don't need to be logged in when using the API -I just tried-. I am not sure what your original question is now. Maybe can you rephrase it now that you have spent a few days working on it ? I am myself learning this API and made some progress. – TNTanuki Dec 24 '14 at 10:00
-1

One can use Plug and play solutions AKA App builders such as Appmaker.xyz in order to create an end-user app.

Felix josemon
  • 932
  • 1
  • 7
  • 14
  • The question is how to build own native app for woo commerce . He was not looking for ready made apps and stack over flow is not a platform to promote commercial products I think . – sreekanth balu Jun 03 '21 at 05:43