Reputation: 56727
I'm using C# to retrieve a list of orders from a WooCommerce 2.6 installation through the new REST API.
What I need to do is fetch orders that have one of three possible states, but the API only seems to allow me to filter one status per call. This is part of the code which used to work fine for the WooCommerce 2.5x REST API:
// Create a list of parameters for filtering the result set
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["status"] = "pending,processing,on-hold";
parameters["expand"] = "coupons,products,taxes";
// Use RestSharp to call the API
var client = new RestClient(wooHelper.ApiUrl);
...
var request = new RestRequest(url, Method.GET);
var response = client.Execute(request);
The values in the parameters
dictionary are appended to the API URL, so in the end I get something like this:
https://example.com/wp-json/wc/v1/orders?status=pending,processing,on-hold&expand=coupons,products,taxes&<other parameters for OAUTH>
The 2.5 API used to return a list of orders that had one of the states in status
. Now I'm getting an error saying that status
is not one of the values any
, ...
Is it still possible in one call to retrieve a list of pending, processing or on-hold orders or do I need to perform three separate calls to the API?
EDIT: The actual error JSON is
{
"code" : "rest_invalid_param",
"message" : "Ung\u00fcltige(r) Parameter: status",
"data" : {
"status" : 400,
"params" : {
"status" : "status ist kein any, pending, processing, on-hold, completed, cancelled, refunded, failed"
}
}
}
EDIT 2: Digging through the WooCommerce source code turned up the following code snippet:
/**
* Query args.
*
* @param array $args
* @param WP_REST_Request $request
* @return array
*/
public function query_args( $args, $request ) {
global $wpdb;
// Set post_status.
if ( 'any' !== $request['status'] ) {
$args['post_status'] = 'wc-' . $request['status'];
} else {
$args['post_status'] = 'any';
}
So when passing in multiple statuses, this would turn $args['post_status']
into wc-pending,processing,on-hold
...?
I guess I'll just perform three separate calls instead of waiting for a solution...
Upvotes: 1
Views: 1579
Reputation: 56727
I filed this on GitHub for investigation and it turns out that filtering by multiple status values is no longer supported with the new REST API. (https://github.com/woothemes/woocommerce/issues/11676).
Upvotes: 1