woocommerce / woocommerce-rest-api

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

Products created via batch have no meta_data #290

Closed rinodrummer closed 5 months ago

rinodrummer commented 5 months ago

This morning I installed the latest version of WordPress (6.5) and installed the latest version of WooCommerce (8.7.0) on my Windows 11 machine with PHP 8.3.4.

I'm trying to import many products using the batch endpoint of the REST API, so I created a new key to access and I setted up a Postman collection.

To test it out I created an HTTP request to import an example product with this payload:

{
    "create": [
        {
            "name": "Product from Batch",
            "regular_price": "1.00",
            "short_description": "",
            "meta_data": [
               {
                        "key": "key1",
                        "value": "value1"
                    },
                    {
                        "key": "key2",
                        "value": "value2"
                    },
                    {
                        "key": "key3",
                        "value": "value3"
                    }
            ],
            "categories": []
        }
    ],
    "update": []
}

The response I got back is this one:

{
    "create": [
        {
            "id": 17,
            "name": "Product from Batch",
            "slug": "product-from-batch",
            "permalink": "http://localhost:8080/index.php/prodotto/product-from-batch/",
            "date_created": "2024-04-04T17:02:20",
            "date_created_gmt": "2024-04-04T15:02:20",
            "date_modified": "2024-04-04T17:02:20",
            "date_modified_gmt": "2024-04-04T15:02:20",
            "type": "simple",
            "status": "publish",
            "featured": false,
            "catalog_visibility": "visible",
            "description": "",
            "short_description": "",
            "sku": "",
            "price": "1.00",
            "regular_price": "1.00",
            "sale_price": "",
            "date_on_sale_from": null,
            "date_on_sale_from_gmt": null,
            "date_on_sale_to": null,
            "date_on_sale_to_gmt": null,
            "on_sale": false,
            "purchasable": true,
            "total_sales": 0,
            "virtual": false,
            "downloadable": false,
            "downloads": [],
            "download_limit": -1,
            "download_expiry": -1,
            "external_url": "",
            "button_text": "",
            "tax_status": "taxable",
            "tax_class": "",
            "manage_stock": false,
            "stock_quantity": null,
            "backorders": "no",
            "backorders_allowed": false,
            "backordered": false,
            "low_stock_amount": null,
            "sold_individually": false,
            "weight": "",
            "dimensions": {
                "length": "",
                "width": "",
                "height": ""
            },
            "shipping_required": true,
            "shipping_taxable": true,
            "shipping_class": "",
            "shipping_class_id": 0,
            "reviews_allowed": true,
            "average_rating": "0",
            "rating_count": 0,
            "upsell_ids": [],
            "cross_sell_ids": [],
            "parent_id": 0,
            "purchase_note": "",
            "categories": [
                {
                    "id": 15,
                    "name": "Senza categoria",
                    "slug": "senza-categoria"
                }
            ],
            "tags": [],
            "images": [],
            "attributes": [],
            "default_attributes": [],
            "variations": [],
            "grouped_products": [],
            "menu_order": 0,
            "price_html": "<span class=\"woocommerce-Price-amount amount\"><bdi>1,00&nbsp;<span class=\"woocommerce-Price-currencySymbol\">&euro;</span></bdi></span>",
            "related_ids": [
                16,
                12,
                15
            ],
            "meta_data": [],
            "stock_status": "instock",
            "has_options": false,
            "post_password": "",
            "permalink_template": "http://localhost:8080/index.php/prodotto/%pagename%/",
            "generated_slug": "product-from-batch",
            "_links": {
                "self": [
                    {
                        "href": "http://localhost:8080/index.php/wp-json/wc/v3/products/17"
                    }
                ],
                "collection": [
                    {
                        "href": "http://localhost:8080/index.php/wp-json/wc/v3/products"
                    }
                ]
            }
        }
    ]
}

As you can see, response's meta_data is empty.

Before testing in local, I tested this scenario on another setup too, but obviously I got the same outcome.

I found no solutions or clear answers around about this behavior.

rinodrummer commented 5 months ago

Fixed. I had a spare couple of square brackets wrapping the meta_data.