kloon / woocommerce-rest-api-client-library Goto Github PK
View Code? Open in Web Editor NEWA PHP wrapper for the WooCommerce REST API
License: GNU General Public License v3.0
A PHP wrapper for the WooCommerce REST API
License: GNU General Public License v3.0
I've just made a clean WP 3.8.1 (latest version) installation with WC 2.1.2 (latest version) on a non-SSL, but I can't get these REST API calls working.
If i print_r the objected returned from the "WC_API_Client"-class I get:
WC_API_Client Object (
[_api_url:private] => <my-url>/wc-api/v1/
[_consumer_key:private] => <my-consumer-key>
[_consumer_secret:private] => <my-consumer-secret>
[_is_ssl:private] =>
[_return_as_object:private] => 1 )
When I try to use any of the functions (e.g. $wc_api->get_coupons()), I get no data - and no errors.
I'm a bit confused about the "/wc-api/v1/ part of the url.
Am I doing something completely wrong?
Hey,
Quick question, is there a way to get all orders for a certain product given it's ID without pulling all orders and going through them one by one?
Thanks!
It is unclear how to use the library to filter the results based on custom product taxonomy. Is this possible?
Hi, guys.
I created a function to get all the cancelled orders filtered by limit:
function get_pedidos_cancelados() {
$consumer_key = 'tururu';
$consumer_secret = 'tururu';
$store_url = 'http://ex.ample.com/';
$wc_api = new WC_API_Client( $consumer_key, $consumer_secret, $store_url );
$pedidos = $wc_api->get_orders( array( 'status' => 'cancelled', 'filter[limit]' => 100 ) );
return json_decode( json_encode( $pedidos ), true ); //get orders in array format
}
But instead of fetch the orders the API call returns an error:
Array
(
[errors] => Array
(
[0] => Array
(
[code] => 200
[message] => cURL HTTP error 200
)
)
)
If I use a number between 0 and 13 as the parameter for filter[limit] the API call works well.
I don't know if this could be a bug or I'm missing something.
This automatically keys a site on WPMU site creation when the user is signed up
Not required for solo sites - cut + paste those ones but for MU is's a boon
The endpoint gets all the data you need to capture the keys which can then be used with another sample I've supplied
Soz - not worked on WP for a few years now so trying to remember it all :)
I can tell you this works 100%
$blog_id, 'user_id' => $user_id, 'domain' => $domain, 'path' => $path, 'site_id' => $site_id, 'meta' => $meta, 'login' => $user->data->user_login, 'email' => $user->data->user_email, 'nicename' => $user->data->user_nicename, 'woo_key' => $user->woocommerce_api_consumer_key, 'woo_secret' => $user->woocommerce_api_consumer_secret, 'display_name' => $user->data->display_name)); wp_remote_post($endpoint, array('body' => $body)); } ``` function sitehooks_generate_api_key( $user_id ) { if ( current_user_can( 'edit_user', $user_id ) ) { $user = get_userdata( $user_id ); ``` // consumer key if ( empty( $user->woocommerce_api_consumer_key ) ) { $consumer_key = 'ck_' . hash( 'md5', $user->user_login . date( 'U' ) . mt_rand() ); update_user_meta( $user_id, 'woocommerce_api_consumer_key', $consumer_key ); } // consumer secret if ( empty( $user->woocommerce_api_consumer_secret ) ) { $consumer_secret = 'cs_' . hash( 'md5', $user->ID . date( 'U' ) . mt_rand() ); update_user_meta( $user_id, 'woocommerce_api_consumer_secret', $consumer_secret ); } // permissions update_user_meta( $user_id, 'woocommerce_api_key_permissions', 'read_write' ); } } ```Hi, i want to retrieve product by sku.
I'm using this sentence
print_r( json_encode($wc_api->get_products(array( 'filter[sku]' => 'P' ))));
don't works. why?
else
print_r( json_encode($wc_api->get_products(array( 'filter[created_at_min]' => '2014-10-01' ))));
works ok.
Thankyou
How can I use the API to create a product with one featured image and some categories?
is it possible ?
Tanks in advance
I'm trying to retrieve the PayPal Transaction ID form the order custom fields but it does not show up on the API wc_api->get_orders ().
Can it be done, if so How ?
I know you aren't at the stage of doing POST requests yet (but this may be helpful for future releases when the API supports POST/PUT/DELETE).
$wc_api->make_custom_endpoint_call( 'products/create',
array(
'ID' => '',
'post_type' => 'product',
'menu_order' => '',
'post_status' => 'publish',
'categories' => array('Category1', 'Category2')
it can't make the oauth_signature because it doesn't expect arrays. Is there something I can do to make this work?
I'm developing a shopping cart Site and an App. I want to get product details from DB for my App, So I have recently used latest version of WooCommerce 2.1. And the main point is I don't have SSL in my domain. So my guess is I must use HTTP, And I don't have any idea about this. I found and read this document today. I'm confused at a point, How should I use this?
Where should I place this class-wc-api-client.php
Where should I place this :
What is $store_url?
How should I make requests?
http://mysite.com/wc-api/v2/products
I know that these are basics, This is my first App. So please help me guys.Thanks
I've made a few small hacks to the library as I wanted webhooks
Its a bit basic but works nicely
Line 17
const API_ENDPOINT = 'wc-api/v2/';
Somewhere around line 277 do this
public function get_webhooks() {
return $this->_make_api_call( 'webhooks' );
}
public function set_webhook( $params = array() ) {
return $this->_make_api_call( 'webhooks', array('webhook' => $params), 'POST' );
}
public function delete_webhook( $id ) {
return $this->_make_api_call( 'webhooks/'.(int) $id, array(), 'DELETE' );
}
It really needs some more work - I just delete en-mass a user's hooks and add them all again (don't wanna spend too much time on it if the API changes before release)
Usage is like this...
get_webhooks(); if(isset($delhook->webhooks)) { for($i=0; $iwebhooks); $i++) { $wc_api->delete_webhook($delhook->webhooks[$i]->id); } } $idx = $wc_api->set_webhook(array('topic' => 'customer.created', 'delivery_url' => $hookadd )); $idx = $wc_api->set_webhook(array('topic' => 'customer.updated', 'delivery_url' => $hookadd )); $idx = $wc_api->set_webhook(array('topic' => 'customer.deleted', 'delivery_url' => $hookadd )); $idx = $wc_api->set_webhook(array('topic' => 'order.created', 'delivery_url' => $hookadd )); $idx = $wc_api->set_webhook(array('topic' => 'order.updated', 'delivery_url' => $hookadd )); $idx = $wc_api->set_webhook(array('topic' => 'order.deleted', 'delivery_url' => $hookadd )); $idx = $wc_api->set_webhook(array('topic' => 'product.created', 'delivery_url' => $hookadd )); $idx = $wc_api->set_webhook(array('topic' => 'product.updated', 'delivery_url' => $hookadd )); $idx = $wc_api->set_webhook(array('topic' => 'product.deleted', 'delivery_url' => $hookadd )); $index = $wc_api->get_webhooks(); echo "\n"; print_r( $index ); echo "\n"; This will then POST to wchook.php any customer actions (there's more you can do but that's all I really need for testing) It's all nicely effective and is allowing me to migrate Shopify clients
The fix implemented for issue #14, results in problems for calls that combine multiple selection values, like in the example below, when trying to fetch all "Simple" and "Variable" products in one call:
WC_API_Client::get_products(['type' => 'simple,variable']);
For WooCommerce versions 2.1.6 and before, this results in:
object(stdClass)[225]
public 'errors' =>
array (size=1)
0 =>
object(stdClass)[259]
public 'code' => string 'woocommerce_api_authentication_error' (length=36)
public 'message' => string 'Invalid Signature - provided signature does not match' (length=53)
versions 2.1.7 and later work as expected.
So I noticed that if I changed the API_ENDPOINT from v1 to v2, the GET requests seem to work just fine.
const API_ENDPOINT = 'wc-api/v2/';
I tried making a few new functions to reflect on the new functions of the v2 API. However, they reject my API key.
Example:
public function create_order( $params = array() ) {
return $this->_make_api_call( 'orders/create/', $params, 'POST' );
}
I get as a response:
object(stdClass)[216]
public 'errors' =>
array (size=1)
0 =>
object(stdClass)[217]
public 'code' => string 'woocommerce_api_authentication_error' (length=36)
public 'message' => string 'Invalid Signature - provided signature does not match' (length=53)
Any ideas? The signature is also used for GETs, right?
First of all, fantastic work on this API. It's simple and effective, and I appreciate all your hard work.
Secondly, I am currently experiencing an issue where WC is complaining that "Invalid Signature - provided signature does not match". The WC version i'm trying to access is 2.1.2 and i'm kind of at a loss as to what the problem might be. I've been trying to troubleshoot the generate_oauth_signature() function but to no avail so far.
Have you ever come across this, or do you have any suggestions on things I could check. Cheers =)
In my WooCommerce store, I have product attributes like "Color" that can be chosen by the customer. When I serialize the data from either "get_orders" or "get_order," the resultant XML does not include any reference to these critically important attributes. The "get_product" function pulls attributes just fine, but I need the attributes chosen for the order. What am I missing?
Hi!
I need to get products which post_status
= trash. Those products are not permanently deleted. Do i need to use a filter to get those products, or it's impossible to get it?
Thanks for answer in advance
Say we have Order 1 with Product 123 and SKU ABC. The Order is persisted.
Then we change the SKU for Product 123 from ABC to XYZ.
The backend shows Order 1 with SKU ABC, as it should imho.
However, the API will show Order 1 with SKU XYZ, which is obviously not what is expected.
WooCommerce Version: 2.1.11
Client Library Version: 0.3.1
Getting an 'Invalid Signature' error when I query for anything other than the index method.
I tried dumping the $string_to_sign
from both the Client and the Server at request time and got the following. All parameters match up but on the server end the WooCommerce API adds an additional query parameter to the $string_to_sign
.
For example, if i query for get_products()
it will add
"%26q%3D%252Fwc-api%252Fv1%252Fproducts"
in addition to the consumer key, nonce, and timestamp.
Obviously this changes the string and the hash does not match. Do you have any ideas on how to deal with this?
Hello, I have just a question... Is it possible to search for keywords using this wrapper? if yes, can you help me, because I didn't understand how can I do this!
// Excuse my beginner's English
Hi! What about warehouse API?
Increase and decrease number of products in the warehouse, for example.
Hi,
API V2 has been out for a few months now, when will the php client library be updated to work with the new API?
As far as I discovered from docs, samples and issues $wc_api->get_products() fetches products according to pagination limit (10 for me): to bypass this feature I use $wc_api->get_products(array('filter[limit]' => $wc_api->get_products_count()->count)) to fetch all published products;
the trick seems not to work for customers: $wc_api->get_customers(array('filter[limit]' => $wc_api->get_customers_count()->count)) fetches the same number of customers as $wc_api->get_customers(): 10;
of course customers are much more.
How can I fetch all of them ?
Hello,
i was wondering about this api.
when i was performing this code. it gives me error.
print_r( $wc_api->get_products() );
//error
stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [code] => 0 [message] => cURL HTTP error 0 ) ) )
but when i use this code:
print_r( $wc_api->get_products_count() );
//success
stdClass Object ( [count] => 483 )
it will print the right amount of the product, how was that happened? any solution for this?
If I'm not mistaken, in version 2.1.3 an issue was fixed that caused using filters to fail for requests on non-ssl connections. Calls like the one below would fail prior to 2.1.3:
$api->get_products(['filter[updated_at_min]' => '2014-04-30'])
The fix is mentioned in the changelog for 2.1.3:
Fix - REST API OAuth signature fixed when using filter params
After upgrading to 2.1.8 on my local machine, I noticed the issue seems to be back.
I checked by testing the same call for versions 2.1.3 - 2.1.8, and they work fine for 2.1.3 - 2.1.6. When doing a call like in the above example for versions 2.1.7 and 2.1.8 the json that I'm getting back is (again):
{
"errors": [
{
"code": "woocommerce_api_authentication_error",
"message": "Invalid Signature - provided signature does not match"
}
]
}
Hi.
is possible get orders for several status?
The example shows how to retrieve orders for completed status,
get_orders( $params = array( 'status' => 'completed' ) )
i need to get orders for 'processing', 'on-hold' and 'cancelled'
is possible?
Thanks
Hey,
Using the following code:
$wc_api = new WC_API_Client( $consumer_key, $consumer_secret, $store_url );
$orders = ( $wc_api->get_orders() );
I get back:
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[code] => 200
[message] => cURL HTTP error 200
)
)
)
However, when I add
$wc_api->set_return_as_object(false);
I get a JSON string back, however running json_decode returns a syntax error. I've tried to disabling/enabling WP_Debug, it still fails. I used to get a memory issue with this call (it returns over 650 orders back) but I've increased the memory limit to almost 10x what it used to be but it still won't work right. Any help is much appreciated.
Hi,
I'm trying to implement the create_order function provided in the API v2, however I'm running into issues.
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' );
}
However, when I try to call this function 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"
}
}
}
My code calling the function is:
$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? How can I updated the old wc-api-client to be able to use the new create_order function?
From our experience with the iOS app, about 10-20% of servers fail to pass the HTTP Authorization header correctly, which results in a "Consumer Key is missing" error when authenticating via SSL. The REST API supports a fallback using query string parameters (?consumer_key=123&consumer_secret=abc
) over SSL so we should default the library to use that.
Hi,
I've succesfully tested WooCommerce-REST-API-Client-Library with WC 2.1.7 two hours ago and then I've updated to WC 2.1.12... I have two websites, one with SSL one without SSL and right now WooCommerce-REST-API-Client-Library doesn't work in both cases.
When I used 2.1.7 both of them worked, now the SSL website tells me that the key does not match and the one without SSL gives me cURL 404.
Can you please tell me what to do in order to make them work?
Using latest checked out library version 0.3
WC Version: 2.1.3
Get_index works, but nothing else does, all provide error below
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[code] => woocommerce_api_authentication_error
[message] => Invalid Signature - provided signature does not match
)
)
)
@kloon Any ideas how to update customer details using the Woocommerce V2 REST API? Thanks.
Hi,
Does the Woocommerce API v2 allows a function to get all the products given a category id?
Thanks a lot.
Hi,
I am trying to use the example.php but I am getting: stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [code] => 200 [message] => cURL HTTP error 200 ) ) )
When I check the PHP log here is what I found: client denied by server configuration: /home/miner/public_html/payments/error_log
This is a public website and I have access to cPanel only. Is there anything I can do?
Thanks
Can I get custom field when get a product or products?
Hi,
I updated to latest version of WooCommerce and migrated my site to another server: and now the API shows me this error when I try to fetch orders by status:
$pedidos = $wc_api->get_orders(
array(
'status' => 'cancelled',
'fields' => 'id,order_number,total,payment_details.method_title,created_at,billing_address,customer',
'filter[limit]' => 100
)
);
If I use just one value for "fields" and remove the filter the orders are fetched, otherwise it says:
stdClass Object ( [errors] => Array ( [0] => stdClass Object ( [code] => woocommerce_api_authentication_error [message] => Firma incorrecta - No coindicen las firmas ) ) )
In the previous issue you mentioned that a encoding bug could cause this problem. Could you tell me if this it is the same case here?
I keep getting this,
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[code] => woocommerce_api_authentication_error
[message] => Invalid Signature - provided signature does not match
)
)
)
when calling;
print_r($wc_api->make_custom_endpoint_call("products/",array(),'POST'));
When I call
print_r($wc_api->make_custom_endpoint_call("products",array(),'GET'));
I get no problems though...
hi
how to maintain tracking no and tracking link of on order in woocommerce using rest api.
Hi
i have configured the woocommerce and wordpress on my local machine .
and also i have generated the consumer key and consumer secret for my woocommece application.i needs to access the wordpress application usind REST API
my request url is as follows
localhost/wordpress/index.php?wc-api-route=/wc-api/orders
if i used above url means i got the following erros.
{"errors":[{"code":"woocommerce_api_authentication_error","message":"Consumer Key is missing"}]}
also i have checked with
://localhost/wordpress/wc-api/v1/orders
if i used the above URL means am getting the 404 error.
how to get the woocommerce api endpoints for my local configuration.
Hello There,
I am using this library to try and utilize the API but I get "Invalid Signature - provided signature does not match" when I try to connect. If I swap to https (which we do have an SSL cert setup and forcing secure checkout) then I get "Consumer Key is missing". I am currently on 1AND1 hosting (which is apache) and using the default wordpress .htaccess file so nothing special there. I am also on WC 2.1.3.
I am trying locally the REST API. I fisrtly installed a wordpress app withinin what, a woocommerce one. Then, next, I downloaded the REST-API-Client-Library in order to test it. To do it,i put the folder in my "www" directory and open the example. Nothing displayed on screen. Can anybody help??
Hi,
using this code:
$wc_api = new WC_API_Client( $consumer_key, $consumer_secret, $store_url );
$wc_api->set_return_as_object(false);
$orders = ( $wc_api->get_orders() );
debug($orders);
I get:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'create_post_type_html5' not found or invalid function name in /srv/www/elfenhof/htdocs/eu/wp-includes/plugin.php on line 505
{"orders":[{"id":1221,"order_number":"#1221","created_at":"2014-10-15T14:52:43Z","updated_at":"2014-10-15T15:36:54Z","completed_at":"2014-10-15T15:36:54Z","status":"on-hold","currency":"EUR","total":"395.01","subtotal":"346.50","total_line_items_quantity":42,"total_tax":"65.83","total_shipping":"0.00","cart_tax":"65.84","shipping_tax":"0.00","total_discount":"20.79","cart_discount":"20.79","order_discount":"0.00","shipping_methods":"Free Delivery for orders with a total of 200 EUR or more","payment_details":{"method_id":"bacs","method_title":"\u00dcberweisung","paid":false},"billing_address":{"first_name":"xxx","last_name":"yyy","company":"company Interactive","address_1":"xyz 14","address_2":"","city":"Wien","state":"","postcode":"1060","country":"AT","email":"[email protected]","phone":"123123123"},"shipping_address":{"first_name":"xxx","last_name":"yyy","company":"xxxx yyyy","address_1":"street14","address_2":"","city":"Wien","state":"","postcode":"1060","country":"AT"},"note":"","customer_ip":"213.164.4.122","customer_user_agent":"Mozilla\/5.0 (Windows NT 6.3; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/37.0.2062.124 Safari\/537.36","customer_id":"1","view_order_url":"http:\/\/mysite.com\/my-account\/view-order\/1221","line_items":[{"id":57,"subtotal":"346.50","total":"329.18","total_tax":"65.83","price":"7.84","quantity":42,"tax_class":null,"name":"Cabernet-Merlot 2013","product_id":1217,"sku":""}],"shipping_lines":[{"id":58,"method_id":"gbi_gratisversand_ordervalue","method_title":"Free Delivery for orders with a total of 200 EUR or more","total":"0.00"}],"tax_lines":[{"code":"AT-MWST. 20%-1","title":"MWSt. 20%","total":"65.84","compound":false}],"fee_lines":[],"coupon_lines":[{"id":60,"code":"@@discount@@","amount":"20.79"}],"customer":{"id":1,"created_at":"2014-08-26T13:09:02Z","email":"[email protected]","first_name":"","last_name":"","username":"companyinteractive","last_order_id":"1219","last_order_date":"2014-10-14T13:44:09Z","orders_count":0,"total_spent":"0.00","avatar_url":"http:\/\/0.gravatar.com\/avatar\/ad516503a11cd5ca435acc9bb6523536?s=96","billing_address":{"first_name":"xxx","last_name":"yyy","company":"company Interactive","address_1":"xyz 14","address_2":"","city":"Wien","state":"","postcode":"1060","country":"AT","email":"[email protected]","phone":"123123123"},"shipping_address":{"first_name":"xxx","last_name":"yyy","company":"company","address_1":"street 14","address_2":"","city":"Wien","state":"","postcode":"1060","country":"AT"}}},{"id":1220,"order_number":"#1220","created_at":"2014-10-15T07:22:51Z","updated_at":"2014-10-15T09:20:36Z","completed_at":"2014-10-15T09:20:36Z","status":"cancelled","currency":"EUR","total":"129.40","subtotal":"100.33","total_line_items_quantity":18,"total_tax":"20.07","total_shipping":"9.00","cart_tax":"20.07","shipping_tax":"0.00","total_discount":"0.00","cart_discount":"0.00","order_discount":"0.00","shipping_methods":"Delivery to Austria","payment_details":{"method_id":"paypal","method_title":"PayPal","paid":false},"billing_address":{"first_name":"xxx","last_name":"yyy","company":"xxx yyy","address_1":"street 14","address_2":"","city":"Wien","state":"","postcode":"1060","country":"AT","email":"[email protected]","phone":"123123123"},"shipping_address":{"first_name":"xxx","last_name":"yyy","company":"company Interactive","address_1":"xyz 14","address_2":"","city":"Wien","state":"","postcode":"1060","country":"AT"},"note":"","customer_ip":"213.164.4.122","customer_user_agent":"Mozilla\/5.0 (Windows NT 6.3; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/37.0.2062.124 Safari\/537.36","customer_id":"1","view_order_url":"http:\/\/eu.elfenhof.seb-friedl.de\/my-account\/view-order\/1220","line_items":[{"id":45,"subtotal":"92.08","total":"92.08","total_tax":"18.42","price":"5.42","quantity":17,"tax_class":null,"name":"Blaufr\u00e4nkisch 2013","product_id":173,"sku":""},{"id":46,"subtotal":"8.25","total":"8.25","total_tax":"1.65","price":"8.25","quantity":1,"tax_class":null,"name":"Cabernet-Merlot 2013","product_id":1217,"sku":""}],"shipping_lines":[{"id":47,"method_id":"gbi_nationaler_versand","method_title":"Delivery to Austria","total":"9.00"}],"tax_lines":[{"code":"AT-MWST. 20%-1","title":"MWSt. 20%","total":"20.07","compound":false}],"fee_lines":[],"coupon_lines":[],"customer":{"id":1,"created_at":"2014-08-26T13:09:02Z","email":"[email protected]","first_name":"","last_name":"","username":"companyinteractive","last_order_id":"1219","last_order_date":"2014-10-14T13:44:09Z","orders_count":0,"total_spent":"0.00","avatar_url":"http:\/\/0.gravatar.com\/avatar\/ad516503a11cd5ca435acc9bb6523536?s=96","billing_address":{"first_name":"xxx","last_name":"yyy","company":"company Interactive","address_1":"xyz 14","address_2":"","city":"Wien","state":"","postcode":"1060","country":"AT","email":"[email protected]","phone":"123123123"},"shipping_address":{"first_name":"xxx","last_name":"yyy","company":"company Interactive","address_1":"xyz 14","address_2":"","city":"Wien","state":"","postcode":"1060","country":"AT"}}},{"id":1219,"order_number":"#1219","created_at":"2014-10-14T13:44:09Z","updated_at":"2014-10-14T15:00:21Z","completed_at":"2014-10-14T15:00:21Z","status":"cancelled","currency":"EUR","total":"129.40","subtotal":"100.33","total_line_items_quantity":18,"total_tax":"20.07","total_shipping":"9.00","cart_tax":"20.07","shipping_tax":"0.00","total_discount":"0.00","cart_discount":"0.00","order_discount":"0.00","shipping_methods":"Delivery to Austria","payment_details":{"method_id":"mpay24","method_title":"Credit card","paid":false},"billing_address":{"first_name":"xxx","last_name":"yyy","company":"company Interactive","address_1":"xyz 14","address_2":"","city":"Wien","state":"","postcode":"1060","country":"AT","email":"[email protected]","phone":"123123123"},"shipping_address":{"first_name":"xxx","last_name":"yyy","company":"company Interactive","address_1":"xyz 14","address_2":"","city":"Wien","state":"","postcode":"1060","country":"AT"},"note":"","customer_ip":"213.164.4.122","customer_user_agent":"Mozilla\/5.0 (Windows NT 6.3; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/37.0.2062.124 Safari\/537.36","customer_id":"1","view_order_url":"http:\/\/eu.elfenhof.seb-friedl.de\/my-account\/view-order\/1219","line_items":[{"id":37,"subtotal":"92.08","total":"92.08","total_tax":"18.42","price":"5.42","quantity":17,"tax_class":null,"name":"Blaufr\u00e4nkisch 2013","product_id":173,"sku":""},{"id":38,"subtotal":"8.25","total":"8.25","total_tax":"1.65","price":"8.25","quantity":1,"tax_class":null,"name":"Cabernet-Merlot 2013","product_id":1217,"sku":""}],"shipping_lines":[{"id":39,"method_id":"gbi_nationaler_versand","method_title":"Delivery to Austria","total":"9.00"}],"tax_lines":[{"code":"AT-MWST. 20%-1","title":"MWSt. 20%","total":"20.07","compound":false}],"fee_lines":[],"coupon_lines":[],"customer":{"id":1,"created_at":"2014-08-26T13:09:02Z","email":"[email protected]","first_name":"","last_name":"","username":"companyinteractive","last_order_id":"1219","last_order_date":"2014-10-14T13:44:09Z","orders_count":0,"total_spent":"0.00","avatar_url":"http:\/\/0.gravatar.com\/avatar\/ad516503a11cd5ca435acc9bb6523536?s=96","billing_address":{"first_name":"xxx","last_name":"yyy","company":"company Interactive","address_1":"xyz 14","address_2":"","city":"Wien","state":"","postcode":"1060","country":"AT","email":"[email protected]","phone":"123123123"},"shipping_address":{"first_name":"xxx","last_name":"yyy","company":"company Interactive","address_1":"xyz 14","address_2":"","city":"Wien","state":"","postcode":"1060","country":"AT"}}}]}
Using the default value (return as object):
$wc_api = new WC_API_Client( $consumer_key, $consumer_secret, $store_url );
$orders = ( $wc_api->get_orders() );
debug($orders);
I get:
stdClass Object
(
[errors] => Array
(
[0] => stdClass Object
(
[code] => 200
[message] => cURL HTTP error 200
)
)
)
I tried fiddling around, and it seems that the $return is empty after the json_decode ?!
-- edit: Possibly because the Wordpress warning is shown as part of the response, the json_decode fails because the string is not valid anymore.
This seems to have to do with WP4.0 as the code worked well on the 3.9 version.
Any Ideas? DOM is installed and running, commenting out the avatar_url didn't help either (which did in an older version).
Best regards,
Murph
Im having a problem to pull 426 products.
$wc_api = new WC_API_Client( $consumer_key, $consumer_secret, $store_url );
print_r($wc_api->get_products());
it will only return 4 products which i don't know why?
i test my dev site also 27 products display only 10 of it.
Can you help me to provide any solution?
I've tried this:
$data = $wc_api->get_orders( array( 'status' => 'completed', 'filter[limit]' => 100 ) );
...and also tried just putting the array in the class-wc-api-client.php but that doesn't change anything I can't seem to get anymore than 30 orders returned. I want ALL the orders returned. If I try 31 or higher then I either get a blank page or a bool(false) on the page. I've checked PHP logs and there is nothing there.
Any idea?
Filters return no data with get_products. Just get a blank page with no errors. Tried the following:
get_products( array( 'filter[posts_per_page]' => '-1' ) );
get_products( array( 'filter[q]' => 'search-term' ) );
get_products( array( 'filter[s]' => 'search-term' ) );
get_products( array( 'filter[created_at_min]' => '2013-12-01' ) );
Also tried all functions in the example.php all with 200 response and no php errors but no data.
The api is working as get_index() and get_products() both return data.
How to implement creating new customer using Woocommerce V2 REST API. Thanks.
Hi guys, I'm a newbie.
I'd like to automatically send all new orders to a third party website with its own API, where they would process them.
In my case, it's scalablepress.com. On their docs, they ask for this format to accept a given order:
POST https://api.scalablepress.com/v2/order
EXAMPLE REQUEST
curl "https://api.scalablepress.com/v2/order" \
-u ":f8a2262aa5285c2050e435c5e581cb0c" \
-d "orderToken=c6ae6ca449719e5237d103139255ecdd"
EXAMPLE RESPONSE
{
"total": 202.79,
"shipping": 10.80,
"subtotal": 191.99,
"orderToken": "c6ae6ca449719e5237d103139255ecdd",
"createdAt": "2014-08-15T01:46:02.035Z",
"events": [
{
"name": "quote",
"description": "Quote completed",
"createdAt": "2014-08-15T01:46:02.036Z"
},
{
"name": "order",
"description": "Order placed. Processing",
"createdAt": "2014-08-15T05:50:07.300Z"
}
],
"items": [
{
"type": "dtg",
"designId": "53ed3a23b3730f0e27a66514",
"address": {
"name": "My Customer",
"address1": "123 Scalable Drive",
"city": "West Pressfield",
"state": "CA",
"zip": "12345",
"country": "US"
},
"products": [
{
"productId": "gildan-sweatshirt-crew",
"color": "ash",
"quantity": 12,
"size": "lrg"
}
],
"designUrl": "https://api.scalablepress.com/v2/design/53ed3a23b3730f0e27a66514"
}
],
"orderId": "53ed665ab3730f0e27a66516",
"mode": "test"
}
Is there a chance for me to make the WooCommerce orders to be formatted that way, and to be automatically sent to them?
Many thanks for your help,
Jan
Hi,
Everything worked just fine until today when I have woocommerce_api_authentication_error [message] => oauth_timestamp Parameter missing. I did nothing to the source code. Double-checked and the line "$params['oauth_timestamp'] = time();" is there.
I tried to manually set $paramString in the following code. curl_setopt( $ch, CURLOPT_URL, $this->_api_url . $endpoint . $paramString );
I do not have any oauth_timestamp error but obviously the signature is not good due to the fact that I had "&oauth_signature=".$this->generate_oauth_signature( $params, $method, $endpoint ) and there was no $params set up (did it manually).
So with original client library code I get oauth_timestamp missing and with it modified to include the timestamp manually in the request I get signature error
Please help
Hi,
Have anybody an example for update the stocks of products?
Thanks
Twitter's guide on creating a signature says to "Percent encode every key and value that will be signed."
But, when I percent encode the keys, WooCommerce complains of an invalid signature. This library doesn't seem to be percent encoding the keys.
When I pass these params to generate_oauth_signature
:
$params['m& _e*o_#!=w//'] = "http://lol_cat.com/";
$params['oauth_timestamp'] = "1396562875";
$params['oauth_signature_method'] = "HMAC-SHA256";
they are transformed into:
m& _e*o_#!=w// => http%3A%2F%2Flol_cat.com%2F
oauth_signature_method => HMAC-SHA256
oauth_timestamp => 1396562875
I think this is a consequence of using array_walk
, which can't modify the keys.
This bug also exists in the REST API implementation: https://github.com/woothemes/woocommerce/blob/8b4c81da13332b1d8c6acfc31833f437fad8f5cf/includes/api/class-wc-api-authentication.php#L196-L197
Thoughts?
I'm duplicating this issue in the WooCommerce repo.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.