Title: API REST Woocommerce &#8211; JSON ERROR
Last modified: March 7, 2023

---

# API REST Woocommerce – JSON ERROR

 *  Resolved [biatsalu](https://wordpress.org/support/users/biatsalu/)
 * (@biatsalu)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/api-rest-woocommerce-json-error/)
 * Hello,
   I already have some experience in programming in wordpress along with 
   online stores and integrations with software + online store. We recently created
   an integration for an online store using the woocommerce api to make the calls,
   since there is already something for this purpose, we have to take advantage 
   of it.
 * Turns out, these calls to the woocommerce api constantly give the Syntax Json
   error which makes it a little tiring since it’s not programming errors.
 * I’ll give an example, I have the authentication working correctly using the code
   below:
 *     ```wp-block-code
       // AUTH
       require __DIR__ . '/vendor/autoload.php';
       use Automattic\WooCommerce\Client;
       $woocommerce = new Client(
           API_URL,
           CONSUMER_KEY,
           CONSUMER_SECRET,
           [
               'wp_api' => true,
               'version' => 'wc/v3',
               'query_string_auth' => true,
               'verify_ssl' => false
           ]
       );
       // END: AUTH
       ```
   
 * And I will query the information of an existing product using the following code(
   where the $pid variable returns the product id):
 *     ```wp-block-code
       print_r($woocommerce->get('products/'.$pid));
       ```
   
 * Only in this example above, it is all correct according to the api documentation
   at this URL [https://woocommerce.github.io/woocommerce-rest-api-docs/](https://woocommerce.github.io/woocommerce-rest-api-docs/).
   Just using the get function to return the product information I want gives the
   following error, every time. There are times it works, other times it keeps giving
   the same error and it’s not because the permalinks aren’t changed because in 
   fact they are, the permalinks don’t change by themselves. Error:
 *     ```wp-block-code
       Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: JSON ERROR: Syntax error in /media/servidordev/www/SITE_XPTO/import/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:411 Stack trace: #0 /media/servidordev/www/SITE_XPTO/import/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php(455): Automattic\WooCommerce\HttpClient\HttpClient->processResponse() #1 /media/servidordev/www/SITE_XPTO/import/vendor/automattic/woocommerce/src/WooCommerce/Client.php(69): Automattic\WooCommerce\HttpClient\HttpClient->request() #2 /media/servidordev/www/SITE_XPTO/import/import.php(581): Automattic\WooCommerce\Client->put() #3 /media/servidordev/www/SITE_XPTO/import/import.php(637): update_produto() #4 /media/servidordev/www/SITE_XPTO/import/import.php(700): import_produtos() #5 /media/servidordev/www/SITE_XPTO/import/import.php(706): run_only_product() #6 {main} thrown in /media/servidordev/www/SITE_XPTO/import/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php on line 411
       ```
   
 * This import.php file, which contains the api and the calling functions, is added
   to a cronjob to read an XML every X time and send products from the software 
   to the online store. Any idea to solve my problem?
    -  This topic was modified 3 years, 3 months ago by [biatsalu](https://wordpress.org/support/users/biatsalu/).

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Igor H](https://wordpress.org/support/users/ihereira/)
 * (@ihereira)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/api-rest-woocommerce-json-error/#post-16537750)
 * Hello,
 * It appears that there is a “Syntax error” on JSON. Mostly that happens when PHP
   errors are being thrown on the site, or perhaps someone forgot to disable PHP’s`
   display_errors`. 
   Please check under _**WooCommerce > System Status > Logs **_(
   if any other error is visible, try to fix it before using the REST API).
 * Hope this helps.
 *  Thread Starter [biatsalu](https://wordpress.org/support/users/biatsalu/)
 * (@biatsalu)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/api-rest-woocommerce-json-error/#post-16540576)
 * Hi,
 * After checking the woocommerce logs I get the same json syntax error every time
   and it’s not a problem with the php code going from the import.php file, because
   there are times when it works without giving any errors. We have the display_errors
   also disabled
 *     ```wp-block-code
       2023-03-08T10:00:03+00:00 CRITICAL Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: JSON ERROR: Syntax error in /media/servidordev/www/SITEXPTO/import/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:411
       Stack trace:
       #0 /media/servidordev/www/SITEXPTO/import/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php(455): Automattic\WooCommerce\HttpClient\HttpClient->processResponse()
       #1 /media/servidordev/www/SITEXPTO/import/vendor/automattic/woocommerce/src/WooCommerce/Client.php(69): Automattic\WooCommerce\HttpClient\HttpClient->request()
       #2 /media/servidordev/www/SITEXPTO/import/import.php(584): Automattic\WooCommerce\Client->put()
       #3 /media/servidordev/www/SITEXPTO/import/import.php(640): update_produto()
       #4 /media/servidordev/www/SITEXPTO/import/import.php(681): import_produtos()
       #5 /media/servidordev/www/SITEXPTO/import/import.php(708): run_import()
       #6 {main}
         thrown em /media/servidordev/www/SITEXPTO/import/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php na linha 411
   
       2023-03-08T13:00:04+00:00 CRITICAL Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: JSON ERROR: Syntax error in /media/servidordev/www/SITEXPTO/import/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:411
       Stack trace:
       #0 /media/servidordev/www/SITEXPTO/import/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php(455): Automattic\WooCommerce\HttpClient\HttpClient->processResponse()
       #1 /media/servidordev/www/SITEXPTO/import/vendor/automattic/woocommerce/src/WooCommerce/Client.php(69): Automattic\WooCommerce\HttpClient\HttpClient->request()
       #2 /media/servidordev/www/SITEXPTO/import/import.php(584): Automattic\WooCommerce\Client->put()
       #3 /media/servidordev/www/SITEXPTO/import/import.php(640): update_produto()
       #4 /media/servidordev/www/SITEXPTO/import/import.php(681): import_produtos()
       #5 /media/servidordev/www/SITEXPTO/import/import.php(708): run_import()
       #6 {main}
         thrown em /media/servidordev/www/SITEXPTO/import/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php na linha 411
       ```
   
 *  [xue28 (woo-hc)](https://wordpress.org/support/users/xue28/)
 * (@xue28)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/api-rest-woocommerce-json-error/#post-16545694)
 * Hi [@biatsalu](https://wordpress.org/support/users/biatsalu/)
 * Thanks for reaching out!
 * This is a fairly complex development topic that would require customization to
   do it. Since custom coding is outside our scope of support, I am leaving this
   thread open for a bit to see if anyone can chime in to help you out.
 * For questions related to development and custom coding, your best bet is to ask
   on any of these channels for support. We’re lucky to have a great community of
   open-source developers for WooCommerce, and many of our developers hang out there,
   too.
    - [WooCommerce Developer Resources Portal](https://developer.woocommerce.com/)
    - [WooCommerce Advanced Facebook group](https://www.facebook.com/groups/advanced.woocommerce/)
    - [WooCommerce Community Forum](https://wordpress.org/support/plugin/woocommerce/)
    - [WooCommerce Developer Slack Channel](https://woocommerce.com/community-slack/)
    - Hire a [WooCommerce Expert](https://woocommerce.com/experts/)
 * Hope this helps!
 *  Thread Starter [biatsalu](https://wordpress.org/support/users/biatsalu/)
 * (@biatsalu)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/api-rest-woocommerce-json-error/#post-16546685)
 * For those who have this kind of problems, my problem was solved by increasing
   the php resources:
 * max_execution_time I set it to 50000 and the memory_limit I set it to 2G, it 
   never gave the error again.
 * It seems that the woocommerce api pulls a lot for resources and starts giving
   syntax errors out of nowhere. Because when it gives a Json error, it appears 
   behind the curl error logs exceeded…
 *  Thread Starter [biatsalu](https://wordpress.org/support/users/biatsalu/)
 * (@biatsalu)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/api-rest-woocommerce-json-error/#post-16567032)
 * Apparently, there is still the problem of json syntax error frequently, but it
   no longer gives curl limit error.
 * Any idea what it could be? I have all error_logs disabled, and the file I’m working
   on has no PHP error.
 * The woocommerce logs show the same error I see in the file I am running.
 * ![](https://i0.wp.com/i.imgur.com/O2iywyk.png?ssl=1)
    -  This reply was modified 3 years, 2 months ago by [biatsalu](https://wordpress.org/support/users/biatsalu/).
 *  [Saif](https://wordpress.org/support/users/babylon1999/)
 * (@babylon1999)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/api-rest-woocommerce-json-error/#post-16569762)
 * Hello [@biatsalu](https://wordpress.org/support/users/biatsalu/),
   [According to a user here](https://wordpress.org/support/topic/uncaught-automatticwoocommercehttpclienthttpclientexception-json-error/),
   changing the permalink settings to default solved the issue which makes sense
   as it will re-write the rules of the `.htaccess` file.Let us know how it goes!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘API REST Woocommerce – JSON ERROR’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [integration](https://wordpress.org/support/topic-tag/integration/)

 * 6 replies
 * 4 participants
 * Last reply from: [Saif](https://wordpress.org/support/users/babylon1999/)
 * Last activity: [3 years, 2 months ago](https://wordpress.org/support/topic/api-rest-woocommerce-json-error/#post-16569762)
 * Status: resolved