Dmitriy Kozyatinskiy
Dmitriy Kozyatinskiy

Reputation: 170

Group products using Woocommerce REST API

I'm trying to create a grouped products using latest version of Woocommerce REST API. I managed to create a product with type grouped and a few products with type simple. But how do I actually group them together? The grouped_products array, which contain IDs of grouped products is read only and parent_id property is not what I'm looking for. Any solutions?

Upvotes: 0

Views: 751

Answers (1)

user982124
user982124

Reputation: 4622

The grouped_products property is now editable in the WooCommerce REST API v2. It was previously marked as READ ONLY but that only applies to v1 of the REST API. With v2 of the REST API you can create a grouped product and set the grouped_products array like this:

curl -X POST https://example.com/wp-json/wc/v2/products \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "name": "Test grouped product",
  "type": "grouped",
  "grouped_products": [1, 2, 3]
}'

where 1, 2 and 3 are the child simple products to be included in the grouped product.

Upvotes: 0

Related Questions