woocommerce / woocommerce-rest-api

This is the WooCommerce core REST API Package. It runs standalone as a feature plugin too.
70 stars 46 forks source link

API issue: Invalid parameter error when defining an empty string for sale_price #121

Closed redelschaap closed 4 years ago

redelschaap commented 4 years ago

Describe the bug We connect to a couple dozen of WooCommerce shops using the API. Since a few days, we get the following error when sending an empty string for the "sale_price" key on variations:

{
    "code": "rest_invalid_param",
    "message": "Invalid parameter(s): sale_price",
    "data": {
        "status": 400,
        "params": {
            "sale_price": "sale_price is not of type number."
        }
    }
}

To Reproduce Steps to reproduce the behavior:

  1. Send a POST request to https://domain.com/wp-json/wc/v3/products/{productId}/variations/{variationId} with valid data:
    {
    "sale_price": ""
    }
  2. Get a 400 Bad Request response.

Expected behavior Update the sale price with an empty value.

Isolating the problem (mark completed items with an [x]):

WordPress Environment

``` ` ### WordPress Environment ### WordPress address (URL): https://***.com Site address (URL): https://***.com WC Version: 3.9.0 REST API Version: ✔ 1.0.6 Log Directory Writable: ✔ WP Version: 5.3.2 WP Multisite: – WP Memory Limit: 512 MB WP Debug Mode: – WP Cron: ✔ Language: en_GB External object cache: – ### Server Environment ### Server Info: Apache PHP Version: 7.0.33 - We recommend using PHP version 7.2 or above for greater performance and security. How to update your PHP version PHP Post Max Size: 32 MB PHP Time Limit: 30 PHP Max Input Vars: 5000 cURL Version: 7.35.0 OpenSSL/1.0.1f SUHOSIN Installed: – MySQL Version: 5.5.5-10.1.40-MariaDB-1~trusty Max Upload Size: 32 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔ ### Database ### WC Database Version: 3.8.1 WC Database Prefix: wp_ Total Database Size: 149.03MB Database Data Size: 104.15MB Database Index Size: 44.88MB wp_woocommerce_sessions: Data: 20.02MB + Index: 2.02MB + Engine InnoDB wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_order_items: Data: 0.25MB + Index: 0.09MB + Engine InnoDB wp_woocommerce_order_itemmeta: Data: 3.52MB + Index: 2.03MB + Engine InnoDB wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_comments: Data: 3.52MB + Index: 3.33MB + Engine InnoDB wp_duplicator_packages: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_[company-name]_brand_form_subscribers: Data: 1.52MB + Index: 0.00MB + Engine InnoDB wp_[company-name]_contact_form_subscribers: Data: 1.52MB + Index: 0.00MB + Engine InnoDB wp_[company-name]_event_forms_subscribers: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_mollie_pending_payment: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_omnisend_logs: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_options: Data: 5.14MB + Index: 0.22MB + Engine InnoDB wp_postmeta: Data: 45.58MB + Index: 26.94MB + Engine InnoDB wp_posts: Data: 13.50MB + Index: 3.53MB + Engine InnoDB wp_termmeta: Data: 0.06MB + Index: 0.06MB + Engine InnoDB wp_terms: Data: 0.31MB + Index: 0.28MB + Engine InnoDB wp_term_relationships: Data: 1.27MB + Index: 0.44MB + Engine InnoDB wp_term_taxonomy: Data: 0.33MB + Index: 0.34MB + Engine InnoDB wp_tinvwl_items: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_tinvwl_lists: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_usermeta: Data: 4.52MB + Index: 4.03MB + Engine InnoDB wp_users: Data: 0.42MB + Index: 0.36MB + Engine InnoDB wp_wc_admin_notes: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_wc_customer_lookup: Data: 0.08MB + Index: 0.06MB + Engine InnoDB wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB wp_wc_order_product_lookup: Data: 0.14MB + Index: 0.19MB + Engine InnoDB wp_wc_order_stats: Data: 0.09MB + Index: 0.08MB + Engine InnoDB wp_wc_order_tax_lookup: Data: 0.08MB + Index: 0.06MB + Engine InnoDB wp_wc_product_meta_lookup: Data: 0.13MB + Index: 0.28MB + Engine InnoDB wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB wp_wpfm_backup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB wp_yoast_seo_links: Data: 0.13MB + Index: 0.05MB + Engine InnoDB wp_yoast_seo_meta: Data: 1.48MB + Index: 0.00MB + Engine InnoDB ### Post Type Counts ### acf: 12 acf-field: 241 acf-field-group: 12 attachment: 5057 custom-css-js: 2 customize_changeset: 1 [company-name]_brands: 248 [company-name]_events: 11 [company-name]_locations: 8 [company-name]_notify: 5 imgl_item: 1 nav_menu_item: 28 oembed_cache: 7 page: 17 post: 83 product: 329 product_variation: 394 revision: 3938 scheduled-action: 1723 shop_coupon: 19 shop_order: 1359 shop_order_refund: 207 wishlist: 23 woo_discount: 1 ### Security ### Secure connection (HTTPS): ❌ Your store is not using HTTPS. Learn more about HTTPS and SSL Certificates. Hide errors from visitors: ✔ ### Active Plugins (37) ### ACF Content Analysis for Yoast SEO: by Thomas Kräftner ViktorFroberg marol87 pekz0r angrycreative Team Yoast – 2.3.0 Advanced Custom Fields PRO: by Elliot Condon – 5.8.7 Schema - All In One Schema Rich Snippets: by Brainstorm Force – 1.6.0 Classic Editor: by WordPress Contributors – 1.5 CO2ok for WooCommerce: by – 1.0.5.5 – Not tested with the active version of WooCommerce Actionable Google Analytics: by Tatvic – CC-V3-2.2 – Not tested with the active version of WooCommerce Disable Comments: by Samir Shah – 1.10.2 Duplicate Post: by Enrico Battocchi – 3.2.4 Duplicator: by Snap Creek – 1.3.24 Facebook for WooCommerce: by Facebook – 1.9.15 – Not tested with the active version of WooCommerce [company-name] Brand Form: by wavelabs – 1.0 [company-name] Contact Form: by wavelabs – 1.0 [company-name] Event Forms: by wavelabs – 1.0 [company-name]: Events: by Wavelabs – [company-name]: Locations & Brands: by Wavelabs – [company-name]: Newsletter: by Wavelabs – [company-name]: Notifications: by Wavelabs – Loco Translate: by Tim Whitlock – 2.3.1 Mollie Payments for WooCommerce: by Mollie – 5.4.2 – Not tested with the active version of WooCommerce Nav Menu Roles: by Kathy Darling – 1.9.5 Omnisend for Woocommerce: by Omnisend – 1.7.2 – Not tested with the active version of WooCommerce Post Types Order: by Nsp Code – 1.9.4.2 Regenerate Thumbnails: by Alex Mills (Viper007Bond) – 3.1.2 Tawk.to Live Chat: by Tawkto – 0.4.1 Category Order and Taxonomy Terms Order: by Nsp-Code – 1.5.7.1 WooCommerce Wishlist Plugin: by TemplateInvaders – 9999 – Not tested with the active version of WooCommerce WooCommerce Ajax add to cart: by WooCommerce Ajax add to cart – 999999999 – Not tested with the active version of WooCommerce Woo Discount Rules: by Flycart Technologies LLP – 1.9.2 – Not tested with the active version of WooCommerce WooCommerce PostNL: by PostNL – 3.1.6 – Not tested with the active version of WooCommerce WooCommerce Admin: by WooCommerce – 0.24.0 – Not tested with the active version of WooCommerce WooCommerce Google Analytics Integration: by WooCommerce – 1.4.17 WooCommerce Login Popup and Shortcodes: by Phpbits Creative Studio – 1.0.2 – Not tested with the active version of WooCommerce WP WooCommerce Mailchimp: by Saint Systems – 2.3.7 – Not tested with the active version of WooCommerce WooCommerce: by Automattic – 3.9.0 Yoast SEO Premium: by Team Yoast – 12.9.1 WP File Manager: by mndpsingh287 – 5.6 wpMandrill: by Mandrill – 1.33 ### Inactive Plugins (0) ### ### Settings ### API Enabled: ✔ Force SSL: – Currency: EUR (€) 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 WooCommerce.com: – ### WC Pages ### Shop base: woocommerce/woocommerce#4 - /shop/ Basket: woocommerce/woocommerce#5 - /bag/ Checkout: woocommerce/woocommerce#6 - /checkout/ My account: woocommerce/woocommerce#7 - /my-account/ Terms and conditions: woocommerce/woocommerce#89 - /terms-conditions/ ### Theme ### Name: _[company-name] Version: 1.1.0 Author URL: https://wavelabs.nl 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 ### Overrides: [company-name]-master/woocommerce/archive-product.php version 2.0.0 is out of date. The core version is 3.4.0 [company-name]-master/woocommerce/cart/cart-empty.php version 3.1.0 is out of date. The core version is 3.5.0 [company-name]-master/woocommerce/cart/cart-shipping.php version 3.2.0 is out of date. The core version is 3.6.0 [company-name]-master/woocommerce/cart/cart-totals.php [company-name]-master/woocommerce/cart/cart.php version 3.3.0 is out of date. The core version is 3.8.0 [company-name]-master/woocommerce/cart/cross-sells.php [company-name]-master/woocommerce/checkout/form-billing.php version 3.0.9 is out of date. The core version is 3.6.0 [company-name]-master/woocommerce/checkout/form-checkout.php version 2.3.0 is out of date. The core version is 3.5.0 [company-name]-master/woocommerce/checkout/form-coupon.php version 3.3.0 is out of date. The core version is 3.4.4 [company-name]-master/woocommerce/checkout/form-pay.php version 3.3.0 is out of date. The core version is 3.4.0 [company-name]-master/woocommerce/checkout/form-shipping.php version 3.0.9 is out of date. The core version is 3.6.0 [company-name]-master/woocommerce/checkout/payment-method.php version 2.3.0 is out of date. The core version is 3.5.0 [company-name]-master/woocommerce/checkout/payment.php version 3.3.0 is out of date. The core version is 3.5.3 [company-name]-master/woocommerce/checkout/review-order.php version 3.3.0 is out of date. The core version is 3.8.0 [company-name]-master/woocommerce/checkout/terms.php version 3.1.1 is out of date. The core version is 3.4.0 [company-name]-master/woocommerce/checkout/thankyou.php version 3.2.0 is out of date. The core version is 3.7.0 [company-name]-master/woocommerce/content-product.php version 3.0.0 is out of date. The core version is 3.6.0 [company-name]-master/woocommerce/content-product_cat.php [company-name]-master/woocommerce/content-single-product.php version 3.0.0 is out of date. The core version is 3.6.0 [company-name]-master/woocommerce/content-widget-product.php version 2.5.0 is out of date. The core version is 3.5.5 [company-name]-master/woocommerce/global/breadcrumb.php [company-name]-master/woocommerce/global/form-login.php version 3.3.0 is out of date. The core version is 3.6.0 [company-name]-master/woocommerce/loop/add-to-cart.php version 3.0.0 is out of date. The core version is 3.3.0 [company-name]-master/woocommerce/loop/loop-end.php [company-name]-master/woocommerce/loop/loop-start.php version 2.0.0 is out of date. The core version is 3.3.0 [company-name]-master/woocommerce/loop/no-products-found.php [company-name]-master/woocommerce/loop/orderby.php version 2.2.0 is out of date. The core version is 3.6.0 [company-name]-master/woocommerce/loop/pagination.php version 2.2.2 is out of date. The core version is 3.3.1 [company-name]-master/woocommerce/loop/price.php [company-name]-master/woocommerce/loop/rating.php version 3.0.0 is out of date. The core version is 3.6.0 [company-name]-master/woocommerce/loop/result-count.php version 3.0.0 is out of date. The core version is 3.7.0 [company-name]-master/woocommerce/loop/sale-flash.php [company-name]-master/woocommerce/myaccount/dashboard.php [company-name]-master/woocommerce/myaccount/form-edit-account.php version 3.3.0 is out of date. The core version is 3.5.0 [company-name]-master/woocommerce/myaccount/form-edit-address.php version 3.3.0 is out of date. The core version is 3.6.0 [company-name]-master/woocommerce/myaccount/form-login.php version 3.3.0 is out of date. The core version is 3.6.0 [company-name]-master/woocommerce/myaccount/my-account.php version 2.6.0 is out of date. The core version is 3.5.0 [company-name]-master/woocommerce/myaccount/my-address.php [company-name]-master/woocommerce/myaccount/navigation.php [company-name]-master/woocommerce/myaccount/orders.php version 3.2.0 is out of date. The core version is 3.7.0 [company-name]-master/woocommerce/myaccount/view-order.php [company-name]-master/woocommerce/notices/error.php version 3.3.0 is out of date. The core version is 3.9.0 [company-name]-master/woocommerce/notices/notice.php version 1.6.4 is out of date. The core version is 3.9.0 [company-name]-master/woocommerce/notices/success.php version 3.3.0 is out of date. The core version is 3.9.0 [company-name]-master/woocommerce/order/order-details-customer.php version 3.3.0 is out of date. The core version is 3.4.4 [company-name]-master/woocommerce/order/order-details-item.php version 3.0.0 is out of date. The core version is 3.7.0 [company-name]-master/woocommerce/order/order-details.php version 3.3.0 is out of date. The core version is 3.7.0 [company-name]-master/woocommerce/order/tracking.php [company-name]-master/woocommerce/product-searchform.php version 2.5.0 is out of date. The core version is 3.3.0 [company-name]-master/woocommerce/single-product/add-to-cart/simple.php [company-name]-master/woocommerce/single-product/add-to-cart/variable.php [company-name]-master/woocommerce/single-product/add-to-cart/variation-add-to-cart-button.php [company-name]-master/woocommerce/single-product/up-sells.php [company-name]-master/woocommerce/single-product-reviews.php version 3.2.0 is out of date. The core version is 3.6.0 [company-name]-master/woocommerce/single-product.php [company-name]-master/woocommerce/taxonomy-product_cat.php [company-name]-master/woocommerce/taxonomy-product_tag.php Outdated Templates: ❌ Learn how to update ### TI WooCommerce Wishlist Templates ### Overrides: – ### Action Scheduler ### Complete: 1,722 Oldest: 2019-12-27 12:49:20 +0000 Newest: 2020-01-27 12:43:17 +0000 Pending: 1 Oldest: 2020-01-27 13:43:17 +0000 Newest: 2020-01-27 13:43:17 +0000 Canceled: 0 Oldest: – Newest: – In-progress: 0 Oldest: – Newest: – Failed: 0 Oldest: – Newest: – ` ```
juliaamosova commented 4 years ago

Hi @redelschaap,

Thank you for reporting the issue. WooCommerce REST API is being developed in another repository: https://github.com/woocommerce/woocommerce-rest-api.

I am going to move your bug report there so that we could take a look there further.

redelschaap commented 4 years ago

@juliaamosova Thanks!

redelschaap commented 4 years ago

I have some new information: this happens only when you send the request with the following header: Content-Type: application/json. When the request is sent with Content-Type set to application/javascript or text/plan, the request is processed correctly.

While this is a (temporary) work around, we use the automattic/woocommerce package, which has the Content-Type header set to application/json hardcoded.

MasterPCUK commented 4 years ago

Had the same issue, fixed now in

WooCommerce 3.9.1 – 2020-01-28 REST API – Fixed – Product and variations schema to allow remove sale prices, dimensions and weight.

redelschaap commented 4 years ago

I can confirm that this is now fixed in 3.9.1 👍