From 07067ec9601eb33dd59066ca454366619c12dcb7 Mon Sep 17 00:00:00 2001 From: Niels Lange Date: Mon, 30 Jan 2023 11:26:07 +0100 Subject: [PATCH] Document how to add multiple items via batch request (#8266) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Document how to add multiple items via batch request * Remove “Add Items” section title * Remove “data” part from JSON example payload --- src/StoreApi/docs/cart.md | 44 ++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/StoreApi/docs/cart.md b/src/StoreApi/docs/cart.md index 20196360968..2a6185a1802 100644 --- a/src/StoreApi/docs/cart.md +++ b/src/StoreApi/docs/cart.md @@ -14,11 +14,6 @@ - [Update Customer](#update-customer) - [Select Shipping Rate](#select-shipping-rate) -Test: - -- Hello -- Hello 2 - The cart API returns the current state of the cart for the current session or logged in user. All POST endpoints require [Nonce Tokens](nonce-tokens.md) and return the updated state of the full cart once complete. @@ -339,6 +334,45 @@ Returns the full [Cart Response](#cart-response) on success, or an [Error Respon If you want to add supplemental cart item data before it is passed into `CartController::add_to_cart` use the [`woocommerce_store_api_add_to_cart_data`](https://github.com/woocommerce/woocommerce-blocks/blob/4d1c295a2bace9a4f6397cfd5469db31083d477a/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_store_api_add_to_cart_data) filter. +If you want to add multiple items at once, you need to use the batch endpoint: + +```http +POST /wc/store/v1/batch +``` + +The JSON payload for adding multiple items to the cart would look like this: + +```json +{ + "requests": [ + { + "path": "/wc/store/v1/cart/add-item", + "method": "POST", + "cache": "no-store", + "body": { + "id": 26, + "quantity": 1 + }, + "headers": { + "Nonce": "1db1d13784" + } + }, + { + "path": "/wc/store/v1/cart/add-item", + "method": "POST", + "cache": "no-store", + "body": { + "id": 27, + "quantity": 1 + }, + "headers": { + "Nonce": "1db1d13784" + } + } + ] +} +``` + ## Remove Item Remove an item from the cart and return the full cart response, or an error.