kloon / WooCommerce-REST-API-Client-Library

A PHP wrapper for the WooCommerce REST API
GNU General Public License v3.0
356 stars 175 forks source link

Filtration Not Worked #190

Closed itzRamkumar closed 6 years ago

itzRamkumar commented 8 years ago

Hi,

I am getting my client Orders from their site using the API.

Here i get orders by its status , startDate, endDate and Limit..

$result = $client->orders->get('', array('status' => 'Processing', 'filter[limit]' => '-1', 'filter[created_at_min]' => '2016-06-01' , 'filter[created_at_max]' => '2016-07-16' ));

It Returns only 20 Orders but in the Site it has more than 100 Orders.

I tried page also it returns Bad Request Error..

If i set the Limit to 10 it returns 20 in default. Limit and Page Not Worked.

Let me know how can i resolve this issue..

Woocommerce Version : 2.5.5

jaythegeek commented 8 years ago

This is down to pagination and or limits, please provide a limit far greater thant he know orders to make sure you can see them all. For example filter[limit] = 500

Otherwise please use pagination, therefore in your URL you should add on ?page=2

Further information can be found here http://woothemes.github.io/woocommerce-rest-api-docs/?php#pagination

itzRamkumar commented 8 years ago

Hi @memerance i tried both filter[limit]=500 and page=2 it returns only 20 Orders.

I get the result like below

[code] => 200 [headers] => Array ( [Date] => Mon, 25 Jul 2016 06:05:56 GMT [Content-Type] => application/json; charset=UTF-8 [Transfer-Encoding] => chunked [Connection] => keep-alive [Set-Cookie] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => __cfduid=de9307ac926ca0c6ed6f7d1ee8e5a2a551469426754; expires=Tue, 25-Jul-17 06:05:54 GMT; path=/; domain=.mysite.com; HttpOnly [1] => state=vce; expires=Sun, 23-Oct-2016 06:05:55 GMT; Max-Age=7776000; path=/; domain=.mysite.com )

                                                                                                                                        [1] =>  wordpress_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/wordpress/wp-admin
                                                                                                                                    )

                                                                                                                                [1] =>  wordpress_sec_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/wordpress/wp-admin
                                                                                                                            )

                                                                                                                        [1] =>  wordpress_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/wordpress/wp-content/plugins
                                                                                                                    )

                                                                                                                [1] =>  wordpress_sec_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/wordpress/wp-content/plugins
                                                                                                            )

                                                                                                        [1] =>  wordpress_logged_in_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/
                                                                                                    )

                                                                                                [1] =>  wordpress_logged_in_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/wordpress/
                                                                                            )

                                                                                        [1] =>  wordpress_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/
                                                                                    )

                                                                                [1] =>  wordpress_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/wordpress/
                                                                            )

                                                                        [1] =>  wordpress_sec_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/
                                                                    )

                                                                [1] =>  wordpress_sec_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/wordpress/
                                                            )

                                                        [1] =>  wordpressuser_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/
                                                    )

                                                [1] =>  wordpresspass_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/
                                            )

                                        [1] =>  wordpressuser_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/wordpress/
                                    )

                                [1] =>  wordpresspass_07dfc6f9dcae36ced272464079008eeb=+; expires=Sun, 26-Jul-2015 06:05:55 GMT; Max-Age=-31536000; path=/wordpress/
                            )

                        [Link] => Array
                            (
                                [0] =>  ; rel="next"
                                [1] =>  ; rel="last"
                            )

                        [Vary] =>  Cookie
                        [X-CacheHit] =>  MISS
                        [X-Powered-By] =>  PHP/5.5.9-1ubuntu4.14
                        [X-WC-Total] =>  184
                        [X-WC-TotalPages] =>  10
                        [Server] =>  cloudflare-nginx
                        [CF-RAY] =>  2c7d6c3d742e2fed-MAA
                    )

            )
jaythegeek commented 8 years ago

Hey @itzRamkumar, do you have your code on GitHub? If so I can have a look for you! If not, just paste in the full php that you are trying to use, please replace USERNAMES & KEYS with dummy text before doing that!!!

itzRamkumar commented 8 years ago

Hi @memerance

require_once( 'woocommerce-api.php' );

$options = array(
'debug'           => true,
'return_as_array' => false,
'validate_url'    => false,
'timeout'         => 60,
'ssl_verify'      => false,
);

$client = new WC_API_Client( 'http://Mysite.com', 'Key', 'key1', $options );

$result = $client->orders->get(null, array( 'status' => 'Completed' ,'filter[created_at_min]' => '2016-07-01' , 'filter[created_at_max]' => '2016-07-25', 'filter[limit]' => '-1' ) );

print_r($result);

It Returns first 20 Orders only.

I increased the filter[limit] => '500' still it returns the 20 orders only.

if i set the page=>'2' in above array it returns the below error..

Error 502 Ray ID: 2c7fdbc448b12fcf • 2016-07-25 13:11:35 UTC

Bad gateway

You Browser

Working Chennai CloudFlare

Working mysite.com Host

Error What happened?

The web server reported a bad gateway error.

What can I do?

Please try again in a few minutes.

CloudFlare Ray ID: 2c7fdbc448b12fcf • Your IP: 0.0.0.0 • Performance & security by CloudFlare

jaythegeek commented 8 years ago

Hi @itzRamkumar, Ok so, I would usually put the limit filter at the beginning of the code, try this way around;

$result = $client->orders->get( null, array( 'filter[limit]' => '200', filter[created_at_min]' => '2016-07-01' , 'filter[created_at_max]' => '2016-07-25', 'status' => 'completed' ) );

On a side note, be careful with that timeout in the options, if you have too many orders you will get an error if it times out! I would just remove that line entirely ;)

Try the above code, let me know how you get on!

itzRamkumar commented 8 years ago

Hi @memerance i tried with the above code and also remove the timeout still i get 20 orders only.

jaythegeek commented 8 years ago

This may sound like a silly question but are you sure there are not more than 20 orders within your criteria?

Perhaps remove all of the filters and just add the filter[limit]=200

I would not to see the full code before and after to help any further :)

itzRamkumar commented 8 years ago

@memerance i don't need to lie. i just told what i get from the code. this is not a silly question to ask. In woocommerce dashboard my client have more than 150 orders in my filter criteria, so only i ask here. so you don't judge my question is silly or not.

Check this http://stackoverflow.com/questions/37118061/woocommerce-api-only-returning-20-results

this is not only for me

Thanks for your reply.

prestaalba commented 7 years ago

Hi @itzRamkumar @memerance. I test with "filter[limit]" parameters and it works good. I want to know how exactly should I use "page" parameter. Just like "page" or like this " filter[page]"??

By the way, excellent API code. Regards

I found it testing. It just "page". Thanks