WooCommerce API for Mobile Application

I plan to develop my own mobile Android application for WooCommerce stores.

I looked at their REST API documentation here: http://docs.woocommercev2.apiary.io/ I already started checking it out, but when I make different calls

GET /orders say that he returns all orders of the store.

Does anyone know how I can create an enduser application using my API.

eg:

 GET /products 

PUT /order (create an order for a registered user)

GET /order (get registered user orders)

Any idea is welcome :)

Thanks in advance.

+9
android rest api wordpress woocommerce
source share
4 answers

For an http request (and not an ssl protocol such as https ), you should use the OAthu 1.0a framework for authentication. There are many libraries for oauth 1.0a in Java, I use from scribeJava

So do the following steps:

  1. In app/build.gradle in app/build.gradle for dependencies add the following:

    compile 'org.scribe:scribe:1.3.5'

  2. New class like WoocommerceApi for OAuth service provider. important. You have to use
    public class in DefaultApi10a for implementing an 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 should make a 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()); 
+1
source share

According to the documentation, the expected data format is only JSON (unlike the previous XML or Json), but unfortunately there is no additional explanation as to what data structure is expected for each endpoint.

Here is the only example of the 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 answer

 { "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

Given that the API claims to accept POST requests for all relevant endpoints, this should be possible with a purchase order.

0
source share

I would suggest the following steps

First, you can enable Apo 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 ways to interact with woocommerce. Otherwise, using lightweight middleware, it will help connect the woocommerce server and return the JSON data to your application.

Write a service using ionic infrastructure and talk with your thin middleware client. Do not forget to cache data (using local storage) so that you do not get to the server all the time. - Contus M Comm

0
source share

Plug and Play solutions by AKA application developers such as Appmaker.xyz can be used to create an end-user application.

0
source share

All Articles