Using API v2 of WooCommerce

EDIT:
Incase anyone is reading this, I made this post before the v2 api was documented, however documentation is now available, so if you’re having issues, refer to: http://woothemes.github.io/woocommerce-rest-api-docs/#introduction


I’m trying to update the PHP REST API client library found here: https://github.com/kloon/WooCommerce-REST-API-Client-Library.

Read More

I changed the API_ENDPOINT to wc-api/v2/ and I added this function:

public function create_order( $data ) {
    return $this->_make_api_call( 'orders/', $data, 'POST' );
}

I get:

Warning:  rawurldecode() expects parameter 1 to be string, array given in /home/class-wc-api-client-    v2.php on line 441
Warning:  rawurldecode() expects parameter 1 to be string, array given in /home/class-wc-api-client-v2.php on line 441
  object(stdClass)#1801 (1) {
 ["errors"]=>
 array(1) {
   [0]=>
   object(stdClass)#1798 (2) {
     ["code"]=>
     string(3) "401"
     ["message"]=>
     string(19) "cURL HTTP error 401"
   }
 }
}

I am using the following code to call create_order

$data = array(
    "status" => "processing",
    "payment_details" => array("method_id" => "paypal", "method_title" => "PayPal", "paid" => 1),
    "line_items" => array("id" => 123, "subtotal" => 45.00, "total" => 45.00, "total_tax" => 0.00, "price" => 45.00, "quantity" => 1, "name" => "itemName", "product_id" => 123)
);
var_dump($wc_api->create_order($data));

Any help?

Thank you!

Related posts

Leave a Reply

2 comments

  1. Though I didn’t work with WooCommerce API or the API client you mentioned, the first thing I noticed was cURL HTTP error 401, probably authentication error. Please double check consumer key & secret.

    Second thing was warning produced in rawurldecode() function (method). You’re passing array but the function is expecting string. So check that part carefully as well.

  2. At present the rawurlencode issue is present both on the API and in the library you’re using

    The authentication error is because your endpoint is ‘orders/’, it should be ‘orders’ (no slash)