I get the error Error: Invalid signature - provided signature does not match [woocommerce_rest_authentication_error] when useinclude parameter, also I use per_page = 20 works fine when use 10 or lower items. following code work fine.

$orders = $woocommerce->get('orders/', array(
            'per_page' => 20,
            'include' => array(554, 553, 550, 549, 548, 547, 546, 545, 544, 543)
));

If I extend one or more ids then I get the above mention error

$orders = $woocommerce->get('orders/', array(
            'per_page' => 20,
            'include' => array(554, 553, 550, 549, 548, 547, 546, 545, 544, 543, 542, 541)
));

I double check all order ids one by one all are correct, and also I debug by using individual id I get all orders using the following code

$orders = $woocommerce->get('orders/', array(
            'per_page' => 20
));
1

There are 1 answers

0
Viesturs Knopkens On

I spent almost whole day with this issue. There is a little bug in WooCommerce PHP API Library.

To understand this bug you have to take a look at .../src/WooCommerce/HttpClient/OAuth.php:193

\uksort($parameters, 'strcmp');

It sorts parameters (by key), but leaves out nested arrays, although $this->getParameters() uses $this->getSortedParameters(), which is more advanced and sorts also nested arrays.

So here's the problem: if $parameters has nested array with more than 9 elements, $parameters differs from $this->getParameters() and more importantly from signed string $stringToSign, so OAuth throws an error: "Invalid signature - provided signature does not match. [woocommerce_rest_authentication_error]".

Example:

$parameters

[
  'include' => [
    0 => 554,
    1 => 553,
    2 => 550,
    3 => 549,
    4 => 548,
    5 => 547,
    6 => 546,
    7 => 545,
    8 => 544,
    9 => 543,
    10 => 542,
    11 => 541,
  ],
  ...
];

$this-getParameters();

[
  'include' => [
    0 => 554,
    1 => 553,
    10 => 542, // !!!
    11 => 541, // !!!
    2 => 550,
    3 => 549,
    4 => 548,
    5 => 547,
    6 => 546,
    7 => 545,
    8 => 544,
    9 => 543,
  ],
  ...
];

It takes just one small change to solve this issue.

.../src/WooCommerce/HttpClient/OAuth.php:193

\uksort($parameters, 'strcmp');

change to:

$parameters = $this->getSortedParameters($parameters);

I also made a pull request: https://github.com/woocommerce/wc-api-php/pull/278