Asked 8 years ago
22 Dec 2016
Views 1552
web-api

web-api posted

how to get orders from WooCommerce by web api ?

i am building Android/ios app for my WooCommerce store . so to communicate with server i need web api .

so thinking that should i start from scratch to develop web api (REST API) for WooCommerce or there are readily aviliable any API aviliable as open source. if so pls suggest and pls show how can i use it ?

i need WooCommerce store 's REST API for getting products , product detail , orders , order detail etc..
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

yes opensource aviliable for connecting to WooCommerce by API .Pls check WooCommerce-REST-API-Client-Library

 
require_once( 'lib/woocommerce-api.php' );
require_once( 'lib/woocommerce-api.php' );

$options = array(
	'debug'           => true,
	'return_as_array' => false,
	'validate_url'    => false,
	'timeout'         => 30,
	'ssl_verify'      => false,
);

try {

	$client = new WC_API_Client( 'http://your-store-url.com', 'ck_enter_your_consumer_key', 'cs_enter_your_consumer_secret', $options );
        print_r( $client->orders->get() );//will result all orders
        print_r( $client->products->get() );// will get all products
}catch ( WC_API_Client_Exception $e ) {

	echo $e->getMessage() . PHP_EOL;
	echo $e->getCode() . PHP_EOL;

	if ( $e instanceof WC_API_Client_HTTP_Exception ) {

		print_r( $e->get_request() );
		print_r( $e->get_response() );
	}
}

hope it clear
Post Answer