0
votes

I am trying to retrieve all categories using Woocommerce rest API. here is my URL

https://wapi.sriyagcommerce.com//wp-json/wc/v2/products/categories?consumer_key=ck&consumer_secret=cs&per_page=100

while using above url I am getting Error.

code    "rest_invalid_param"
message "Invalid parameter(s): per_page"
data    
status  400
params  
per_page    "per_page must be between 1 (inclusive) and 100 (inclusive)"

I want to increase per page limit. I already have done with products by using below code and want to do the same with categories

function maximum_api_filter($query_params) {
    $query_params['per_page']["maximum"]=100000;
    return $query_params;
}

add_filter('rest_product_collection_params', 'maximum_api_filter');
2
No.. Still searching for answer, I am having more than 300 categoriesGagandeep

2 Answers

2
votes

I must've commented very early in the morning

There is NO Way of increasing the size per page past a 100 Its a limit set by the API team you cannot exceed a 100.

Now I do not know what Your using to develop, But i'd consider using a Collection and just pull the first 100, Index the Page pull a 100 Combine Collections and so on.

But as for Getting all 300 in one instance from one API call that cannot be done sadly.

1
votes

I also face the same problem.

You couldn't increase the list size. Maximum limit in Woocommerce is 100.

You can follow bellow URL pattern to fetch 100 records,
https://www.yourcompany.com/wp-json/wc/v2/products?per_page=100

You can also specify pages with the ?page parameter
https://www.yourcompany.com/wp-json/wc/v2/products?per_page=100&page=2

You can find total number of pages and records from
the X-WP-TotalPages and X-WP-Total HTTP headers.

After getting total page from X-WP-TotalPages you can execute a loop with per_page=100&page=${pageNumber} and increase pageNumber dynamically.
By this approach you can find all records.