wc-api-php: Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: cURL Error: Operation timed out after 30009 milliseconds with 0 bytes received

I want to use the REST API to get products and categories on the front-end of a website and make an infinite scroll. I’m havong some trouble with the php client library, I’m on localhost and I’m not able to fetch data. I get this error

Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: cURL Error: Operation timed out after 30009 milliseconds with 0 bytes received

require __DIR__ . '/vendor/autoload.php';

  use Automattic\WooCommerce\Client;

  $woocommerce = new Client(
      'http://localhost/ladykent/', // Your store URL
      'ck_32...', // Your consumer key
      'cs_0a...', // Your consumer secret
      [
          'wp_api' => true, // Enable the WP REST API integration
          'version' => 'wc/v3', // WooCommerce WP REST API version
          'timeout'=> 30,
          'verify_ssl'=> false,
      ]
  );

If I remove the ssl verification and the timeout, after setting a custom rest route on wordpress I will get instead this error:

add_action( 'rest_api_init', function(){
    register_rest_route('shop/v1', '/categories',
      array(
        'methods' => WP_REST_Server::READABLE,
        'callback' => 'get_shop_categories'
      )
    );
  });
  
  function get_shop_categories( $woocommerce ){
    $data = $woocommerce->get('products/categories');
    $response = new WP_REST_Response( $data, 200 );
    return $response;
  }

Fatal error: Uncaught Error: Call to undefined method WP_REST_Request::get()

Is possible to fix this?

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 2
  • Comments: 17

Most upvoted comments

Solo se debe añadir un timeout:

ejm:

$woocommerce = new Client( $url_API_woo, $ck_API_woo, $cs_API_woo, [
‘wp_api’ => true, ‘version’ => ‘wc/v3’, ‘timeout’ => 400 ] );

Hi everyone,

I was also having the same issue, there were about 300 to 400 products in my Yii project and needs to be exported to wordpress store. I was also facing the same error and I could fix that error by increasing timout amount in settings array like

$woocommerce = new Client(
      'http://localhost/ladykent/', // Your store URL
      'ck_32...', // Your consumer key
      'cs_0a...', // Your consumer secret
      [
          'wp_api' => true, // Enable the WP REST API integration
          'version' => 'wc/v3', // WooCommerce WP REST API version
          'timeout'=> 40000, // it needs to be increased according to your need I increase it to 40000
          'verify_ssl'=> false,
      ]
  );

Solo se debe añadir un timeout:

ejm:

$woocommerce = new Client( $url_API_woo, $ck_API_woo, $cs_API_woo, [ ‘wp_api’ => true, ‘version’ => ‘wc/v3’, ‘timeout’ => 400 ] );

It’s works for me

Same issue here on Nginx as well as Apache. Following the WooCommerce REST API Docs to the letter with $woocommere->get(‘’), I get

`Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: cURL Error: Operation timed out after 2000 milliseconds with 0 bytes received in /automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:417 Stack trace: #0 /vendor/automattic/woocommerce/src/WooCommerce/Client.php(82): Automattic\WooCommerce\HttpClient\HttpClient->request() #1 myplugin-import.php(34): Automattic\WooCommerce\Client->get() #2 /wp-settings.php(377): include_once(‘/sites/dev-impo…’) #3 /wp-config.php(83): require_once(‘/sites/dev-impo…’) #4 /wp-load.php(37): require_once(‘/sites/dev-impo…’) #5 /wp-blog-header.php(13): require_once('/ in /vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php on line 417

	`

Hi, you can check automattic\woocommerce\src\WooCommerce\HttpClient\HttpClient.php here CURLOPT_TIMEOUT set 0 so its infinite loop set