skip to Main Content

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:

AutomatticWooCommerceHttpClientHttpClientException 
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.

4

Answers


  1. Chosen as BEST ANSWER

    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.


  2. Solution : Just change default settings for permalink in wp-admin/options-permalink.php

    Login or Signup to reply.
  3. Check if your URL($site) has ‘https://’

    Login or Signup to reply.
    1. Timezone of POS should be same as timezone of the Woocommerce App
    2. Get WooCommerce API details from, WooCommerce -> Settings -> Advance -> REST API . Enter description, select User & Provide Read/Write Permission. Click here for more info
    3. Change the permalinks option to "Post Name" in WordPress permalink option.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search