WooCommerce REST API > Create product help

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?

btw, have you checked this one?


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…

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

I found the following modification to the Kloon library:

Now it all seems to work

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.

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