phpwordpresswoocommerce-rest-api

WooCommerce API giving JSON Syntax Error on every request


I'm getting a JSON Syntax Error whenever I want to send any request to my Wordpress site.

$woocommerce = new Client(
        $site,
        $key,
        $secret,
        [
            'wp_api'  => true,
            'version' => 'wc/v3',
            'query_string_auth' => true,
        ]
    );
    
    print_r($woocommerce->get('products'));

And when I run the function, I simply get:

Automattic\WooCommerce\HttpClient\HttpClientException 
JSON ERROR: Syntax error

I dont know if there's a way to get more info about the error, cause it's not really explicit.


Solution

  • In the end, the problem came from the URL. Added "www" made the API call work. No documentation about this, the error only saying JSON Syntax Error, was nice clues to find a solution.