Giter Site home page Giter Site logo

woocommerce-rest-api-client-library's Introduction

WooCommerce REST API PHP Client Library

About

A PHP wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library.

Feedback and bug reports are appreciated.

Requirements

PHP 5.2.x cURL WooCommerce 2.2 at least on the store

Getting started

Generate API credentials (Consumer Key & Consumer Secret) under WP Admin > Your Profile.

Setup the library

require_once( 'lib/woocommerce-api.php' );

$options = array(
	'ssl_verify'      => false,
);

try {

	$client = new WC_API_Client( 'http://your-store-url.com', $consumer_key, $consumer_secret, $options );

} catch ( WC_API_Client_Exception $e ) {

	echo $e->getMessage() . PHP_EOL;
	echo $e->getCode() . PHP_EOL;

	if ( $e instanceof WC_API_Client_HTTP_Exception ) {

		print_r( $e->get_request() );
		print_r( $e->get_response() );
	}
}

Options

  • debug (default false) - set to true to add request/response information to the returned data. This is particularly useful for troubleshooting errors.

  • return_as_array (default false) - all methods return data as a stdClass by default, but you can set this option to true to return data as an associative array instead.

  • validate_url (default false) - set this to true to verify that the URL provided has a valid, parseable WC API index, and optionally force SSL when supported.

  • timeout (default 30) - set this to control the HTTP timeout for requests.

  • ssl_verify (default true) - set this to false if you don't want to perform SSL peer verification for every request.

Error handling

Exceptions are thrown when errors are encountered, most will be instances of WC_API_Client_HTTP_Exception which has two additional methods, get_request() and get_response() -- these return the request and response objects to help with debugging.

Methods

Index

  • $client->index->get() - get the API index

Orders

  • $client->orders->get() - get a list of orders
  • $client->orders->get( null, array( 'status' => 'completed' ) ) - get a list of completed orders
  • $client->orders->get( $order_id ) - get a single order

Credit

Copyright (c) 2013-2014 - Gerhard Potgieter, Max Rice and other contributors

License

Released under the GPL3 license

woocommerce-rest-api-client-library's People

Contributors

claudiosanches avatar garypegeot-wic avatar judgej avatar kloon avatar maxrice avatar tillz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

woocommerce-rest-api-client-library's Issues

HTTP: Getting Invalid Signature - provided signature does not match, HTTPS: Consumer Key is missing

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.

Get all products

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?

Invalid Signature - provided signature does not match

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...

create_order API v2

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?

Perform SSL authentication with query string params

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.

How to search for keywords?

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!

message] => Invalid Signature - provided signature does not match

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
)

    )

)

Question

Can I get custom field when get a product or products?

Combining multiple selection values failing for 2.1.6 and before

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.

WooCommerce Signatures

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 =)

custom fields

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 ?

Parameter keys aren't being percent encoded

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.

array_walk( $params, array( $this, 'normalize_parameters' ) );

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.

invalid Signature when using more than one fields for "fields"

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?

Nothing displayed on screen

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??

POST request not working for v2

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?

Convert Result to XML or JSON

Hello.
I'm triying the woocommerce api, but I'm not expert in php.
when execute you php example, i retrieve the result but i dont understand it.

for example.
print_r( $wc_api->get_products() );

is possible to covert the restult of the example.php in xml or json. have you an example?

thanks a lot

products

2.2 WebHooks

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

Get Products by SKU

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

404 issue on 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.

Something cool (auto keys)

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' ); } } ```

Connecting to the mobile app through Rest API

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

  • inside my theme root?

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

How to get products from trash?

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

Get all products

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?

Invalid Signature - provided signature does not match

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?

API V2

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?

Help a newbie: POST orders from WooCommerce to a non-WP platform with its own API

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

Issue with WC 2.1.12

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?

Question: Where should the files be placed?

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?

Get all orders for product

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!

Post JSON data with multi-dimensional arrays

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).

  • I have set up my own plugin that extends the current API (can't wait for 2.2) that does support POST/PUT/DELETE
    • I am using $wc_api->make_custom_endpoint_call to make custom calls to it
    • When I try to send multi-dimensional arrays i.e:

$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?

Get Orders

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

No data get_products() with filters

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.

get_customers

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 ?

cURL HTTP error 200 / client denied by server configuration

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

Using filter parameter failing since 2.1.7?

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"
        }
    ]
}

Fetching orders with filter[limit] returns an error with PHP code

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.

set_return_as_object = false results to weird behavior

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

$wc_api->get_orders() not working correctly

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.

Filter Limit Not Showing All the Orders

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?

How can I access "attributes" selected by customer?

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?

get_products_by_category

Hi,
Does the Woocommerce API v2 allows a function to get all the products given a category id?
Thanks a lot.

Filter by Custom Taxonomies

It is unclear how to use the library to filter the results based on custom product taxonomy. Is this possible?

Issue with oauth_timestamp

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.