WooCommerce REST API > Create product help


#1

I’m trying to figure out how to create a decent API call with PHP to create a product.

I’ve used the client ( https://github.com/kloon/WooCommerce-REST-API-Client-Library ) before, but it does not yet support POST/PUT methods.

But i figured this should be easy to add for myself - but no luck yet…

Anyone got some pointers?


#2

btw, have you checked this one?

http://woothemes.github.io/woocommerce-rest-api-docs/#create-a-product


#3

Yes i have.

I have it working now with a custom call using the Kloon library.

$product = array(
			'sku' => '100001',
			'title' => 'Superduper product',
			'type' => 'simple',
			'regular_price' => '21.50',
			'description' => 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
			'short_description' => 'Short description for product',
			'categories' => array( 'testcat', anothercat' )
		);

		return $this->_make_api_call( 'products', array( 'product' => $product ), 'POST' );

It is creating the product well - but i still get the following error returned:

Warning: rawurldecode() expects parameter 1 to be string, array given in class-wc-api-client.php on line 465 stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [code] => 201 [message] => cURL HTTP error 201 ) ) )

probably because this library isn’t updated for v2 yet or something…

Any suggestions? Or maybe some other easy PHP auth rest client to use for api calls…


#4

Did you try official WordPress REST API that’s in development? https://github.com/WP-API/WP-API


#5

I found the following modification to the Kloon library:

Now it all seems to work


#6

Just a quick note here that version 2.0 of the library is being worked on. You can select the 2.0 branch to see how it’s going so far.


#7

Thanks for the heads up! I will keep an eye on it :slight_smile: