Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access Woocommerce API with Flutter?

Woocommerce API implements Oauth1 with consumer key/secret.

Here is my code to access WordPress API with Flutter

Future<String> getData() async {

var response = await http.get(
    Uri.encodeFull( "http://jalania.com/wp-json/wp/v2/posts" ),
    headers: {"Accept": "application/json"});
this.setState(() {
  data = JSON.decode(response.body);
});
}

I've changed the API url to Woocommerce API, http://jalania.com/wp-json/wc/v2/products and got empty responses.

Does anyone know how to access Woocommerce API with flutter?

like image 332
Panahbiru Avatar asked Oct 30 '25 08:10

Panahbiru


2 Answers

You might wanna use this: https://github.com/lakexyde/dart-woocommerce-api. Though still needs some cleaning but it does work.

Map<String,dynamic> params = {
  "url": 'https://example.com',
  "consumerKey": "ck_XXXXXXXXXXXXXXXXXXXXXXXXX",
  "consumerSecret": "cs_XXXXXXXXXXXXXXXXXXXXXXXX",
  "wpAPI": true,
  "version": 'wc/v2'
}

And then:

WooCommerceAPI wooAPI = new WooCommerceAPI(params);

Hope it helps.

like image 86
lakex Avatar answered Nov 01 '25 23:11

lakex


Need to add the authorization to WooCommerce API. I do not know how to add the authorization parameter in Flutter. But you need to add something like below code.

Future<String> getData() async {

var response = await http.get(
    Uri.encodeFull( "http://jalania.com/wp-json/wp/v2/posts" ),
    authorization:{"consumer_key": "XXXXXXXX1212","consumer_secret":"XXXXX1212"},
    headers: {"Accept": "application/json"});
this.setState(() {
  data = JSON.decode(response.body);
});
}
like image 31
Ajay Ghaghretiya Avatar answered Nov 01 '25 21:11

Ajay Ghaghretiya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!