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?
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.
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);
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With