WooCommerce-REST-API-Client-Library icon indicating copy to clipboard operation
WooCommerce-REST-API-Client-Library copied to clipboard

How do I create a category?

Open dyluck07 opened this issue 9 years ago • 1 comments

I've been banging my head. I've managed to extend the class to GET categories (which was super easy). It doesn't work with POST at all. It gives me a

Error: No route was found matching the URL and request method [woocommerce_api_no_route] 404

Here is the get_categories working:

    public function get_categories( $id = null, $args = array() ) {

        $this->set_request_args( array(
            'method' => 'GET',
            'path'   => array( 'categories', $id ),
            'params' => $args,
        ) );

        return $this->do_request();
    }

Tried the POST method and it doesn't work:

    public function create_categories($data) {

        $this->set_request_args( array(
            'method' => 'POST',
            'path' => 'categories',
            'body' => $data
        ) );

        return $this->do_request();
    }

I've checked woocomerce API documentation and looks as if the syntax is correct...

Here is the url in the error: http://www.mysite.com/wc-api/v2/products/categories?oauth_consumer_key etc... The json error returned shows that method is "POST" too..

Any help would be appreciated! Thanks!

dyluck07 avatar Jul 08 '16 17:07 dyluck07

Answering my own question. IT doesn't work with this version of woocommerce API. Please update this really great tool to work with the new woocommerce api (https://woothemes.github.io/woocommerce-rest-api-docs/) instead of (https://woothemes.github.io/woocommerce-rest-api-docs/v2.html)

dyluck07 avatar Jul 08 '16 23:07 dyluck07