woocommerce / wc-api-php

WooCommerce REST API PHP Library
https://packagist.org/packages/automattic/woocommerce
MIT License
521 stars 160 forks source link

Fatal error -> HttpClientException #348

Closed merciful-player closed 5 months ago

merciful-player commented 5 months ago

Prerequisites

Describe the bug

Not sure how to fix this fatal error: PHP Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: JSON ERROR: Syntax error in /home/itexasnos1111/public_html/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:411

Expected behavior

I am using the Client->put('products/ID', $data) call and it should have updated my product

Actual behavior

PHP Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: JSON ERROR: Syntax error in /home/itexasnos1111/public_html/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:411

Steps to reproduce

PHP Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: JSON ERROR: Syntax error in /home/itexasnos1111/public_html/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:411

WordPress Environment

`

WordPress Environment

WordPress address (URL): https://www.nostexasparts.com Site address (URL): https://www.nostexasparts.com WC Version: 8.6.1 REST API Version: ✔ 8.6.1 WC Blocks Version: ✔ 11.8.0-dev Action Scheduler Version: ✔ 3.7.1 Log Directory Writable: ✔ WP Version: ❌ 6.3.4 - There is a newer version of WordPress available (6.5.2) WP Multisite: – WP Memory Limit: 512 MB WP Debug Mode: – WP Cron: ✔ Language: en External object cache: –

Server Environment

Server Info: Apache PHP Version: 7.4.33 PHP Post Max Size: 128 MB PHP Time Limit: 30 PHP Max Input Vars: 1000 cURL Version: 7.87.0 OpenSSL/1.1.1w

SUHOSIN Installed: – MySQL Version: 5.5.5-10.6.17-MariaDB-cll-lve Max Upload Size: 128 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔

Database

WC Database Version: 6.9.4 WC Database Prefix: wp_ Total Database Size: 409.68MB Database Data Size: 377.61MB Database Index Size: 32.07MB wp_woocommerce_sessions: Data: 27.92MB + Index: 0.93MB + Engine MyISAM wp_woocommerce_api_keys: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_attribute_taxonomies: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_downloadable_product_permissions: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_order_items: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_order_itemmeta: Data: 0.01MB + Index: 0.02MB + Engine MyISAM wp_woocommerce_tax_rates: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_woocommerce_tax_rate_locations: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_shipping_zones: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_shipping_zone_locations: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_woocommerce_shipping_zone_methods: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_payment_tokens: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_payment_tokenmeta: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_woocommerce_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_actionscheduler_actions: Data: 2.09MB + Index: 0.68MB + Engine MyISAM wp_actionscheduler_claims: Data: 0.03MB + Index: 0.07MB + Engine MyISAM wp_actionscheduler_groups: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_actionscheduler_logs: Data: 1.23MB + Index: 0.94MB + Engine MyISAM wp_commentmeta: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_comments: Data: 0.01MB + Index: 0.01MB + Engine MyISAM wp_frmt_form_entry: Data: 0.02MB + Index: 0.03MB + Engine MyISAM wp_frmt_form_entry_meta: Data: 0.27MB + Index: 0.14MB + Engine MyISAM wp_frmt_form_reports: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_frmt_form_views: Data: 0.04MB + Index: 0.08MB + Engine MyISAM wp_give_donormeta: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_give_donors: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_give_formmeta: Data: 0.01MB + Index: 0.01MB + Engine MyISAM wp_give_logmeta: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_give_logs: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_give_paymentmeta: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_jetpack_sync_queue: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_links: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_litespeed_url: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_litespeed_url_file: Data: 0.02MB + Index: 0.08MB + Engine InnoDB wp_options: Data: 26.61MB + Index: 3.61MB + Engine MyISAM wp_participants_database: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_participants_database_fields: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_participants_database_groups: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_pmxi_files: Data: 0.04MB + Index: 0.01MB + Engine MyISAM wp_pmxi_hash: Data: 0.19MB + Index: 0.13MB + Engine MyISAM wp_pmxi_history: Data: 0.14MB + Index: 0.03MB + Engine MyISAM wp_pmxi_images: Data: 1.62MB + Index: 0.14MB + Engine MyISAM wp_pmxi_imports: Data: 32.03MB + Index: 0.02MB + Engine MyISAM wp_pmxi_posts: Data: 0.39MB + Index: 0.13MB + Engine MyISAM wp_pmxi_templates: Data: 0.03MB + Index: 0.00MB + Engine MyISAM wp_postmeta: Data: 154.62MB + Index: 11.67MB + Engine MyISAM wp_posts: Data: 126.77MB + Index: 9.77MB + Engine MyISAM wp_sm_sessions: Data: 0.14MB + Index: 0.10MB + Engine MyISAM wp_termmeta: Data: 0.15MB + Index: 0.10MB + Engine MyISAM wp_terms: Data: 0.04MB + Index: 0.09MB + Engine MyISAM wp_term_relationships: Data: 0.91MB + Index: 1.75MB + Engine MyISAM wp_term_taxonomy: Data: 0.04MB + Index: 0.04MB + Engine MyISAM wp_usermeta: Data: 0.28MB + Index: 0.17MB + Engine MyISAM wp_users: Data: 0.02MB + Index: 0.02MB + Engine MyISAM wp_wc_admin_notes: Data: 0.08MB + Index: 0.00MB + Engine MyISAM wp_wc_admin_note_actions: Data: 0.04MB + Index: 0.01MB + Engine MyISAM wp_wc_category_lookup: Data: 0.01MB + Index: 0.02MB + Engine MyISAM wp_wc_customer_lookup: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_wc_download_log: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wc_orders: Data: 0.02MB + Index: 0.11MB + Engine InnoDB wp_wc_orders_meta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_addresses: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_wc_order_coupon_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wc_order_operational_data: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_product_lookup: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_wc_order_stats: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_wc_order_tax_lookup: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wc_product_attributes_lookup: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_product_download_directories: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_product_meta_lookup: Data: 0.48MB + Index: 0.49MB + Engine MyISAM wp_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_reserved_stock: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wc_tax_rate_classes: Data: 0.00MB + Index: 0.01MB + Engine MyISAM wp_wc_webhooks: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wpda_csv_uploads: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_csv_uploads_BACKUP_20230317180731: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_csv_uploads_BACKUP_20230407153106: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_csv_uploads_BACKUP_20230515151803: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_logging: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_logging_BACKUP_20230317180731: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_logging_BACKUP_20230407153106: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_logging_BACKUP_20230515151803: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_media: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_media_BACKUP_20230317180731: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_media_BACKUP_20230407153106: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_media_BACKUP_20230515151803: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_menus: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_menus_BACKUP_20230317180731: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_menus_BACKUP_20230407153106: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_menus_BACKUP_20230515151803: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_project: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wpda_project_BACKUP_20230317180731: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_project_BACKUP_20230407153106: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_project_BACKUP_20230515151803: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_project_page: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wpda_project_page_BACKUP_20230317180731: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_project_page_BACKUP_20230407153106: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_project_page_BACKUP_20230515151803: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_project_table: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_project_table_BACKUP_20230317180731: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_project_table_BACKUP_20230407153106: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_project_table_BACKUP_20230515151803: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_publisher: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wpda_publisher_BACKUP_20230317180731: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_publisher_BACKUP_20230407153106: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_publisher_BACKUP_20230515151803: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_table_design: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_table_design_BACKUP_20230317180731: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_table_design_BACKUP_20230407153106: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_table_design_BACKUP_20230515151803: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_table_settings: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_table_settings_BACKUP_20230317180731: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_table_settings_BACKUP_20230407153106: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wpda_table_settings_BACKUP_20230515151803: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wt_iew_action_history: Data: 0.05MB + Index: 0.00MB + Engine MyISAM wp_wt_iew_cron: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wt_iew_ftp: Data: 0.00MB + Index: 0.00MB + Engine MyISAM wp_wt_iew_mapping_template: Data: 0.01MB + Index: 0.00MB + Engine MyISAM wp_yoast_seo_links: Data: 0.01MB + Index: 0.01MB + Engine MyISAM wp_yoast_seo_meta: Data: 0.26MB + Index: 0.22MB + Engine MyISAM

Post Type Counts

attachment: 59742 customize_changeset: 1 forminator_forms: 1 give_forms: 1 give_payment: 3 ml-slider: 1 nav_menu_item: 6 page: 20 post: 16121 product: 6671 revision: 69 shop_coupon: 13 shop_order: 1 shop_order_refund: 14 ticket: 236 ticket_history: 308 ticket_log: 2 ticket_reply: 65 wooframework: 20 wp_global_styles: 1

Security

Secure connection (HTTPS): ✔ Hide errors from visitors: ✔

Active Plugins (23)

Awesome Support: by Awesome Support Team – 6.1.11 Breadcrumb NavXT: by John Havlik – 7.3.0 Facebook for WooCommerce: by Facebook – 3.2.0 Forminator: by WPMU DEV – 1.29.3 Site Kit by Google: by Google – 1.125.0 Jetpack: by Automattic – 13.3.1 LiteSpeed Cache: by LiteSpeed Technologies – 6.2.0.1 Social Login: by OneAll Social Login – 5.7 PHP Compatibility Checker: by WP Engine – 1.6.3 Product Import Export for WooCommerce: by WebToffee – 2.4.3 Really Simple SSL: by Really Simple Plugins – 8.1.0 Regenerate Thumbnails: by Alex Mills (Viper007Bond) – 3.1.6 Simple Social Icons: by OsomPress – 3.2.4 TikTok: by TikTok – 1.2.5 USPS Simple Shipping for Woocommerce: by dangoodman – 1.10.3 WooCommerce Accepted Payment Methods: by jameskoster – 0.7.0 WooCommerce PayPal Checkout Gateway: by WooCommerce – 2.1.3 WooCommerce Legacy REST API: by WooCommerce – 1.0.1 WooCommerce Shipping & Tax: by WooCommerce – 2.5.5 WooCommerce: by Automattic – 8.6.1 WP All Import Pro: by Soflyy – 4.8.7 WP Data Access Premium: by Passionate Programmers B.V. – 5.3.9 WP All Import - WooCommerce Import Add-On Pro: by Soflyy – 4.0.0

Inactive Plugins (18)

Akismet Anti-spam: Spam Protection: by Automattic - Anti-spam Team – 5.3.2 Fast Secure Contact Form: by fastsecure – 4.0.56 Go Daddy Quick Setup: by GoDaddy.com LLC – 1.04

MetaSlider: by MetaSlider – 3.70.2 One Click Demo Import: by OCDI – 3.2.1 P3 (Plugin Performance Profiler): by GoDaddy.com – 1.5.4 Participants Database: by Roland Barker xnau webdesign – 2.5.8.1

TemplatesNext ToolKit: by TemplatesNext – 3.2.9 Welcome to WordPress: by Starfield Technologies – 1.0 WooCommerce Admin: by WooCommerce – 3.3.2 WooCommerce Helper: by WooCommerce – 1.7.2 – Network enabled WooCommerce Payment Gateway - Inspire: by innerfire – 2.1.27 WooDojo: by WooThemes – 1.5.4 WooPayments: by Automattic – 7.5.3 Woo Shortcodes Kit: by Alberto G. – 2.0.2 WordPress Importer: by wordpressdotorg – 0.8.2 WP Simple Pay Lite: by WP Simple Pay – 4.9.0 Yoast SEO: by Team Yoast – 22.6

Must Use Plugins (2)

p3-profiler.php: by – WordPress automation by Installatron: by –

Settings

API Enabled: ✔ Force SSL: ✔ Currency: USD ($) Currency Position: left Thousand Separator: , Decimal Separator: . Number of Decimals: 2 Taxonomies: Product Types: external (external) grouped (grouped) simple (simple) variable (variable)

Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5)

Connected to Woo.com: ✔ Enforce Approved Product Download Directories: – HPOS feature screen enabled: – HPOS feature enabled: – Order datastore: WC_Order_Data_Store_CPT HPOS data sync enabled: ✔

WC Pages

Shop base: woocommerce/woocommerce#6 - / Cart: woocommerce/woocommerce#7 - /cart/ Checkout: woocommerce/woocommerce#8 - /checkout/ My account: woocommerce/woocommerce#9 - /my-account/ Terms and conditions: ❌ Page not set

Theme

Name: i-excel Version: 1.7.9 Author URL: http://templatesnext.org/ Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme WooCommerce Support: ✔

Templates

Archive Template: Your theme has a woocommerce.php file you will not be able to override the woocommerce/archive-product.php custom template since woocommerce.php has priority over archive-product.php. This is intended to prevent display issues.

Overrides: –

Admin

Enabled Features: activity-panels analytics product-block-editor coupons core-profiler customer-effort-score-tracks import-products-task experimental-fashion-sample-products shipping-smart-defaults shipping-setting-tour homescreen marketing mobile-app-banner navigation onboarding onboarding-tasks product-variation-management product-virtual-downloadable product-external-affiliate product-grouped product-linked remote-inbox-notifications remote-free-extensions payment-gateway-suggestions shipping-label-banner subscriptions store-alerts transient-notices woo-mobile-welcome wc-pay-promotion wc-pay-welcome-page

Disabled Features: customize-store minified-js new-product-management-experience product-pre-publish-modal settings async-product-editor-category-field

Daily Cron: ✔ Next scheduled: 2024-05-02 22:32:45 +00:00 Options: ✔ Notes: 203 Onboarding: completed

Action Scheduler

Complete: 1,287 Oldest: 2024-04-01 02:33:31 +0000 Newest: 2024-05-02 02:26:24 +0000

Failed: 3,712 Oldest: 2019-10-05 11:29:34 +0000 Newest: 2023-06-04 22:05:02 +0000

Pending: 10 Oldest: 2024-05-02 02:27:24 +0000 Newest: 2024-05-02 21:09:24 +0000

Status report information

Generated at: 2024-05-02 02:26:27 +00:00 `

Isolating the problem

barryhughes commented 5 months ago

It sounds like this may be an issue with the API client library, rather than a problem with the core WooCommerce plugin, so I'm going to transfer it across to the relevant project.

https://github.com/woocommerce/wc-api-php

barryhughes commented 5 months ago

@merciful-player we'd need more information to be able to help. For example, in my own testing and given a correctly initialized API client, a PUT request that updates an existing product seems to work nicely:

$woocommerce->put( 'products/123', [
  'name' => 'Change of product name',
] );

I'm not sure what's going wrong in your case.

Thanks!

merciful-player commented 5 months ago

@barryhughes Yes, the product does exist. I can make "get" & "post" requests w/o issues, but "put" & "delete" give me Fatal Errors

The payload for "put" is:

$data = [ 'stock_quantity' => 0 ];
$woocommerce->put('products/ID#', $data);

The payload for "delete" is: $woocommerce->delete('products/ID#', ['force' => true]);

Hope you can help, I've been using these commands for about a year now, and on May 1, they started giving me Fatal Errors.

barryhughes commented 5 months ago

OK, thanks!

So, probably, there has been a change of some kind in the server-side environment. The error you are seeing comes from HttpClient::processResponse() which, just as it sounds, processes the response from the server: it expects to receive well-formed JSON but in your case it presumably is not. Common reasons for this:

Since it is likely a problem that is specific to your environment (rather than a bug in this package), I'm going to close the issue. Some next steps you can try:

I hope that helps!

merciful-player commented 5 months ago

Thank you, I will work on that this weekend.