Commit ecd6887cd08 for woocommerce

commit ecd6887cd08b5f820ed1eb569905adb459b3d61c
Author: Ryan Ray <ryan.ray@automattic.com>
Date:   Fri Dec 4 15:43:45 2026 -0500

    Document WooCommerce 11.2.2 REST authentication and Cart Items (#70686)

    * Document WooCommerce 11.2.2 integration compatibility

    * Apply review feedback on the 11.2.2 developer docs

    Remove the CSV importer compatibility page, which reviewers want handled
    as an advisory. Apply the authentication timing and query string key
    suggestions, note the callback's HTTP 200 requirement, and fix small
    wording issues.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * Send the Cart-Token in the Cart Items read examples

    The list and single item examples now use the same Cart-Token as the
    add, update and delete examples, so they read the same cart.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * Clarify when REST API keys identify the current user

    ---------

    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

diff --git a/docs/apis/rest-api/authentication.mdx b/docs/apis/rest-api/authentication.mdx
index bcb8a033542..1057a387d2a 100644
--- a/docs/apis/rest-api/authentication.mdx
+++ b/docs/apis/rest-api/authentication.mdx
@@ -8,7 +8,7 @@ import TabItem from '@theme/TabItem';

 # Authentication

-WooCommerce includes two ways to authenticate with the WP REST API. It is also possible to authenticate using any [WP REST API authentication](http://v3.wp-api.org/guide/authentication/) plugin or method.
+WooCommerce includes two ways to authenticate with the WP REST API. It is also possible to authenticate using any [WP REST API authentication](https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/) plugin or method.

 ## REST API keys

@@ -16,33 +16,27 @@ Pre-generated keys can be used to authenticate use of the REST API endpoints. Ne

 REST API keys do not authenticate requests to the [Store API](/docs/apis/store-api/) (`/wp-json/wc/store/`). Since WooCommerce 11.3.1, a Store API request that sends a key is not run as the key's user.

-### Generating API keys in the WordPress admin interface
-
-To create or manage keys for a specific WordPress user, go to WooCommerce > Settings > Advanced > REST API.
+### Authentication timing for extensions

-*Note: Keys/Apps was found at WooCommerce > Settings > API > Key/Apps prior to WooCommerce 3.4.*
+Starting in WooCommerce 11.2.2, WooCommerce API keys are authenticated only during a WordPress REST request. WordPress usually determines the current user before it identifies the request as a REST request, so WooCommerce normally resolves the API key's user on `rest_authentication_errors` at priority 8. In that request flow, if no other authentication method has identified a user, `get_current_user_id()` returns `0` on `init`, `wp_loaded`, and `rest_api_init`. Use a REST endpoint's permission callback for checks that depend on the authenticated user.

-![WooCommerce REST API keys settings](v3/images/woocommerce-api-keys-settings.png)
+The `woocommerce_rest_is_request_to_rest_api` filter is evaluated only after WordPress identifies the request as a REST endpoint, so it can no longer enable API keys outside REST requests. After a key is accepted, later `rest_authentication_errors` callbacks receive `true`. Other authentication methods can identify a user earlier. For requests using a logged-in WordPress cookie, include a valid `wp_rest` nonce. If a request sends both a logged-in cookie and an API key without the nonce, WordPress treats the request as unauthenticated and a protected endpoint returns a 401 response. An invalid cookie nonce returns a 403 response. See [WordPress REST API authentication](https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/#cookie-authentication).

-Click the "Add Key" button. In the next screen, add a description and select the WordPress user you would like to generate the key for. Use of the REST API with the generated keys will conform to that user's WordPress roles and capabilities.
+### Generating API keys in the WordPress admin interface

-Choose the level of access for this REST API key, which can be _Read_ access, _Write_ access or _Read/Write_ access. Then click the "Generate API Key" button and WooCommerce will generate REST API keys for the selected user.
+To create or manage keys for a specific WordPress user, go to **WooCommerce > Settings > Advanced > REST API keys**.

-![Creating a new REST API key](v3/images/woocommerce-creating-api-keys.png)
+Select **Add key**, or **Create an API key** if the store has no keys yet. On the next screen, add a description and select the WordPress user you want to generate the key for. Use of the REST API with the generated keys will conform to that user's WordPress roles and capabilities.

-Now that keys have been generated, you should see two new keys, a QRCode, and a Revoke API Key button. These two keys are your Consumer Key and Consumer Secret.
+Choose the level of access for this REST API key, which can be _Read_ access, _Write_ access or _Read/Write_ access. Then select **Generate API key** to generate the keys for the selected user.

-![Generated REST API key](v3/images/woocommerce-api-key-generated.png)
+The generated keys appear as **Consumer key** and **Consumer secret**, alongside a QRCode and a **Revoke key** link. Copy the consumer secret before leaving the page; it will be hidden afterward.

 If the WordPress user associated with an API key is deleted, the API key will cease to function. API keys are not transferred to other users.

 ### Auto generating API keys using our Application Authentication Endpoint

-This endpoint can be used by any APP to *allow users to generate API keys* for your APP. This makes integration with WooCommerce API easier because the user only needs to grant access to your APP via a URL. After being redirected back to your APP, the API keys will be sent back in a separate POST request.
-
-The following image illustrates how this works:
-
-![Authentication Endpoint flow](v3/images/woocommerce-auth-endpoint-flow.png)
+This endpoint can be used by any APP to *allow users to generate API keys* for your APP. This makes integration with WooCommerce API easier because the user only needs to grant access to your APP via a URL. After the user approves, WooCommerce sends the API keys to the callback URL in a separate POST request. When the callback succeeds, WooCommerce redirects the user to the return URL.

 :::warning
 This endpoint works exclusively for users to generate API keys and facilitate integration between the WooCommerce REST API and an application. In no way is this endpoint intended to be used as login method for customers.
@@ -56,7 +50,7 @@ This endpoint works exclusively for users to generate API keys and facilitate in
 | `scope`        | string | Level of access. Available: `read`, `write` and `read_write` `MANDATORY`                                                                        |
 | `user_id`      | string | User ID in your APP. For your internal reference, used when the user is redirected back to your APP. NOT THE USER ID IN WOOCOMMERCE `MANDATORY` |
 | `return_url`   | string | URL the user will be redirected to after authentication `MANDATORY`                                                                             |
-| `callback_url` | string | URL that will receive the generated API key. Note: this URL should be over **HTTPS** `MANDATORY`                                                |
+| `callback_url` | string | URL that will receive the generated API key. This URL must use **HTTPS**. `MANDATORY`                                                |

 #### Creating an authentication endpoint URL

@@ -69,9 +63,9 @@ You must use the `/wc-auth/v1/authorize` endpoint and pass the above parameters

 ```shell
 # Bash example
-STORE_URL='http://example.com'
+STORE_URL='https://example.com'
 ENDPOINT='/wc-auth/v1/authorize'
-PARAMS="app_name=My App Name&scope=read_write&user_id=123&return_url=http://app.com/return-page&callback_url=https://app.com/callback-endpoint"
+PARAMS="app_name=My App Name&scope=read_write&user_id=123&return_url=https://app.com/return-page&callback_url=https://app.com/callback-endpoint"
 QUERY_STRING="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$PARAMS")"
 QUERY_STRING=$(echo $QUERY_STRING | sed -e "s/%20/\+/g" -e "s/%3D/\=/g" -e "s/%26/\&/g")

@@ -84,13 +78,13 @@ echo "$STORE_URL$ENDPOINT?$QUERY_STRING"
 ```javascript
 const querystring = require('querystring');

-const store_url = 'http://example.com';
+const store_url = 'https://example.com';
 const endpoint = '/wc-auth/v1/authorize';
 const params = {
   app_name: 'My App Name',
   scope: 'read_write',
   user_id: 123,
-  return_url: 'http://app.com/return-page',
+  return_url: 'https://app.com/return-page',
   callback_url: 'https://app.com/callback-endpoint'
 };
 const query_string = querystring.stringify(params).replace(/%20/g, '+');
@@ -103,13 +97,13 @@ console.log(store_url + endpoint + '?' + query_string);

 ```php
 <?php
-$store_url = 'http://example.com';
+$store_url = 'https://example.com';
 $endpoint = '/wc-auth/v1/authorize';
 $params = [
     'app_name' => 'My App Name',
     'scope' => 'write',
     'user_id' => 123,
-    'return_url' => 'http://app.com',
+    'return_url' => 'https://app.com',
     'callback_url' => 'https://app.com'
 ];
 $query_string = http_build_query( $params );
@@ -124,13 +118,13 @@ echo $store_url . $endpoint . '?' . $query_string;
 ```python
 from urllib.parse import urlencode

-store_url = 'http://example.com'
+store_url = 'https://example.com'
 endpoint = '/wc-auth/v1/authorize'
 params = {
     "app_name": "My App Name",
     "scope": "read_write",
     "user_id": 123,
-    "return_url": "http://app.com/return-page",
+    "return_url": "https://app.com/return-page",
     "callback_url": "https://app.com/callback-endpoint"
 }
 query_string = urlencode(params)
@@ -144,13 +138,13 @@ print("%s%s?%s" % (store_url, endpoint, query_string))
 ```ruby
 require "uri"

-store_url = 'http://example.com'
+store_url = 'https://example.com'
 endpoint = '/wc-auth/v1/authorize'
 params = {
   app_name: "My App Name",
   scope: "read_write",
   user_id: 123,
-  return_url: "http://app.com/return-page",
+  return_url: "https://app.com/return-page",
   callback_url: "https://app.com/callback-endpoint"
 }
 query_string = URI.encode_www_form(params)
@@ -173,14 +167,13 @@ puts "#{store_url}#{endpoint}?#{query_string}"
 }
 ```

-Example of the screen that the user will see:
-
-![Authentication Endpoint example](v3/images/woocommerce-auth-endpoint-example.png)
+The authorization screen identifies the app, its requested permissions, and the domain receiving credentials. The user can approve or deny the request.

 #### Notes

 - While redirecting the user using `return_url`, you are also sent `success` and `user_id` parameters as query strings.
 - `success` sends `0` if the user denied, or `1` if authenticated successfully.
+- Your `callback_url` must respond with an HTTP `200` status. If the request fails or returns any other status, WooCommerce deletes the new key and shows the user an error instead of redirecting to `return_url`.
 - Use `user_id` to identify the user when redirected back to the (`return_url`) and also remember to save the API Keys when your `callback_url` is posted to after auth.
 - The auth endpoint will send the API Keys in JSON format to the `callback_url`, so it's important to remember that some languages such as PHP will not display it inside the `$_POST` global variable, in PHP you can access it using `$HTTP_RAW_POST_DATA` (for old PHP versions) or `file_get_contents('php://input');`.
 - The URL generated must have all query string values encoded.
@@ -270,95 +263,11 @@ woocommerce = WooCommerce::API.new(
   </TabItem>
 </Tabs>

-Occasionally some servers may not parse the Authorization header correctly (if you see a "Consumer key is missing" error when authenticating over SSL, you have a server issue). In this case, you may provide the consumer key/secret as query string parameters instead.
-
-> Example for servers that not properly parse the Authorization header:
-
-<Tabs>
-  <TabItem value="curl" label="cURL">
-
-```shell
-curl https://www.example.com/wp-json/wc/v3/orders?consumer_key=123&consumer_secret=abc
-```
-
-  </TabItem>
-  <TabItem value="js" label="JavaScript">
-
-```javascript
-const WooCommerceRestApi = require("@woocommerce/woocommerce-rest-api").default;
-// import WooCommerceRestApi from "@woocommerce/woocommerce-rest-api"; // Supports ESM
-
-const WooCommerce = new WooCommerceRestApi({
-  url: 'https://example.com',
-  consumerKey: 'consumer_key',
-  consumerSecret: 'consumer_secret',
-  version: 'wc/v3',
-  queryStringAuth: true // Force Basic Authentication as query string true and using under HTTPS
-});
-```
-
-  </TabItem>
-  <TabItem value="php" label="PHP">
-
-```php
-<?php
-require __DIR__ . '/vendor/autoload.php';
-
-use Automattic\WooCommerce\Client;
-
-$woocommerce = new Client(
-    'https://example.com',
-    'consumer_key',
-    'consumer_secret',
-    [
-        'wp_api' => true,
-        'version' => 'wc/v3',
-        'query_string_auth' => true // Force Basic Authentication as query string true and using under HTTPS
-    ]
-);
-?>
-```
-
-  </TabItem>
-  <TabItem value="python" label="Python">
-
-```python
-from woocommerce import API
-
-wcapi = API(
-    url="https://example.com",
-    consumer_key="consumer_key",
-    consumer_secret="consumer_secret",
-    wp_api=True,
-    version="wc/v3",
-    query_string_auth=True  # Force Basic Authentication as query string true and using under HTTPS
-)
-```
-
-  </TabItem>
-  <TabItem value="ruby" label="Ruby">
-
-```ruby
-require "woocommerce_api"
-
-woocommerce = WooCommerce::API.new(
-  "https://example.com",
-  "consumer_key",
-  "consumer_secret",
-  {
-    wp_json: true,
-    version: "wc/v3",
-    query_string_auth: true  # Force Basic Authentication as query string true and using under HTTPS
-  }
-)
-```
-
-  </TabItem>
-</Tabs>
+If the server does not pass the `Authorization` header to WordPress, WooCommerce still accepts `consumer_key` and `consumer_secret` as query string parameters over HTTPS. This isn't recommended because URLs end up in logs, so fix the server configuration instead. See the [WordPress REST API authentication troubleshooting guide](https://developer.wordpress.org/rest-api/frequently-asked-questions/#why-is-authentication-not-working) for examples.

 ## Authentication over HTTP

-You must use [OAuth 1.0a "one-legged" authentication](http://tools.ietf.org/html/rfc5849) to ensure REST API credentials cannot be intercepted by an attacker. Typically you will use any standard OAuth 1.0a library in the language of your choice to handle the authentication, or generate the necessary parameters by following the following instructions.
+WooCommerce supports [OAuth 1.0a "one-legged" authentication](https://www.rfc-editor.org/rfc/rfc5849) for HTTP requests. OAuth signs requests but does not encrypt their contents or protect responses from interception. Use HTTPS to protect data in transit. Typically you will use a standard OAuth 1.0a library in the language of your choice, or generate the necessary parameters by following the instructions below.

 ### Creating a signature

@@ -376,7 +285,7 @@ Collect and normalize your parameters. This includes all `oauth_*` parameters ex

 These values need to be encoded into a single string which will be used later on. The process to build the string is very specific:

-1. [Percent encode](https://dev.twitter.com/oauth/overview/percent-encoding-parameters) every key and value that will be signed.
+1. [Percent encode](https://www.rfc-editor.org/rfc/rfc5849#section-3.6) every key and value that will be signed.
 2. Sort the list of parameters alphabetically by encoded key.
 3. For each key/value pair:
 	- Append the encoded key to the output string.
@@ -402,9 +311,9 @@ To encode the HTTP method, request URL, and parameter string into a single strin

 1. Set the output string equal to the uppercase **HTTP Method**.
 2. Append the `&` character to the output string.
-3. [Percent encode](https://dev.twitter.com/oauth/overview/percent-encoding-parameters) the URL and append it to the output string.
+3. [Percent encode](https://www.rfc-editor.org/rfc/rfc5849#section-3.6) the URL and append it to the output string.
 4. Append the `&` character to the output string.
-5. [Percent encode](https://dev.twitter.com/oauth/overview/percent-encoding-parameters) the parameter string and append it to the output string.
+5. [Percent encode](https://www.rfc-editor.org/rfc/rfc5849#section-3.6) the parameter string and append it to the output string.

 > Example signature base string:

@@ -420,7 +329,7 @@ In PHP you can use the [hash_hmac](http://php.net/manual/en/function.hash-hmac.p

 HMAC-SHA1 or HMAC-SHA256 are the only accepted hash algorithms.

-If you are having trouble generating a correct signature, you'll want to review the string you are signing for encoding errors. The [authentication source](https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-rest-authentication.php#L185) can also be helpful in understanding how to properly generate the signature.
+If you are having trouble generating a correct signature, you'll want to review the string you are signing for encoding errors. The [authentication source](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/class-wc-rest-authentication.php) can also be helpful in understanding how to properly generate the signature.

 ### OAuth tips

@@ -430,6 +339,6 @@ If you are having trouble generating a correct signature, you'll want to review
 * The OAuth nonce can be any randomly generated 32 character (recommended) string that is unique to the consumer key.
 * The OAuth timestamp should be the unix timestamp at the time of the request. The REST API will deny any requests that include a timestamp outside of a 15 minute window to prevent replay attacks.
 * You must use the store URL provided by the index when forming the base string used for the signature, as this is what the server will use. (e.g. if the store URL includes a `www` sub-domain, you should use it for requests)
-* Note that the request body is *not* signed as per the OAuth spec.
+* Form-encoded POST parameters are included when WooCommerce verifies the OAuth signature. JSON request bodies are not included in the signature. Use HTTPS to protect the entire request and response in transit.
 * If including parameters in your request, it saves a lot of trouble if you can order your items alphabetically.
 * Authorization header is supported starting WooCommerce 3.0.
diff --git a/docs/apis/store-api/resources-endpoints/cart-items.md b/docs/apis/store-api/resources-endpoints/cart-items.md
index f09ff3634de..ac85c131ecf 100644
--- a/docs/apis/store-api/resources-endpoints/cart-items.md
+++ b/docs/apis/store-api/resources-endpoints/cart-items.md
@@ -1,5 +1,7 @@
 # Cart Items API

+Requests that add, update, or delete cart items require a valid [Nonce Token](/docs/apis/store-api/nonce-tokens) or [Cart Token](/docs/apis/store-api/cart-tokens). The examples below use a `CART_TOKEN` environment variable containing the Cart Token for the cart to change. Obtain one from the response headers of a `GET /cart` request.
+
 ## List Cart Items

 ```http
@@ -9,7 +11,7 @@ GET /cart/items
 There are no extra parameters needed to use this endpoint.

 ```sh
-curl "https://example-store.com/wp-json/wc/store/v1/cart/items"
+curl --header "Cart-Token: $CART_TOKEN" "https://example-store.com/wp-json/wc/store/v1/cart/items"
 ```

 **Example response:**
@@ -234,7 +236,7 @@ GET /cart/items/:key
 | `key`     | string |   Yes    | The key of the cart item to retrieve. |

 ```sh
-curl "https://example-store.com/wp-json/wc/store/v1/cart/items/c74d97b01eae257e44aa9d5bade97baf"
+curl --header "Cart-Token: $CART_TOKEN" "https://example-store.com/wp-json/wc/store/v1/cart/items/c74d97b01eae257e44aa9d5bade97baf"
 ```

 **Example response:**
@@ -333,13 +335,15 @@ POST /cart/items/
 | Attribute   | Type    | Required | Description                                                                                          |
 | :---------- | :------ | :------: | :--------------------------------------------------------------------------------------------------- |
 | `id`        | integer |   Yes    | The cart item product or variation ID.                                                               |
-| `quantity`  | integer |   Yes    | Quantity of this item in the cart.                                                                   |
-| `variation` | array   |   Yes    | Chosen attributes (for variations) containing an array of objects with keys `attribute` and `value`. |
+| `quantity`  | number  |   No     | Quantity to add. Defaults to the product's minimum quantity.                                         |
+| `variation` | array   |   No     | Chosen attributes for a variation, as objects with `attribute` and `value` keys.                      |

 ```sh
-curl --request POST https://example-store.com/wp-json/wc/store/v1/cart/items?id=100&quantity=1
+curl --header "Cart-Token: $CART_TOKEN" --request POST "https://example-store.com/wp-json/wc/store/v1/cart/items?id=100&quantity=1"
 ```

+When adding a variable product by its parent ID, provide the selected variation attributes. For a specific variation whose attributes are fixed, you can pass its variation ID without repeating those attributes. If a variation uses an Any attribute, provide a valid selection for that attribute even when passing the variation ID. Missing or mismatched selections return a `400` error.
+
 For an example response, see [Single Cart Item](#single-cart-item).

 If you're looking to add multiple items to the cart at once, please take a look at [batching](/docs/apis/store-api/resources-endpoints/cart#add-item).
@@ -355,12 +359,16 @@ PUT /cart/items/:key
 | Attribute  | Type    | Required | Description                        |
 | :--------- | :------ | :------: | :--------------------------------- |
 | `key`      | string  |   Yes    | The key of the cart item to edit.  |
-| `quantity` | integer |   Yes    | Quantity of this item in the cart. |
+| `quantity` | number  |   No     | New quantity of this item in the cart. |

 ```sh
-curl --request PUT https://example-store.com/wp-json/wc/store/v1/cart/items/e369853df766fa44e1ed0ff613f563bd?quantity=10
+curl --header "Cart-Token: $CART_TOKEN" --request PUT "https://example-store.com/wp-json/wc/store/v1/cart/items/e369853df766fa44e1ed0ff613f563bd?quantity=10"
 ```

+Starting in WooCommerce 11.2.2, a nonnumeric `quantity` returns a `400` error and leaves the cart unchanged. WooCommerce normalizes numeric values with `wc_stock_amount()` and validates them against the product's quantity limits. By default, stock amounts are converted to integers; extensions can change this behavior.
+
+If an update returns `401` or `403`, check that the Cart Token or nonce is valid for the current cart session. For a `409` response, check that the item key belongs to that cart. For a `400` response, check that the quantity is numeric and meets the product's quantity limits.
+
 For an example response, see [Single Cart Item](#single-cart-item).

 ## Delete Single Cart Item
@@ -376,7 +384,7 @@ DELETE /cart/items/:key
 | `key`     | string |   Yes    | The key of the cart item to edit. |

 ```sh
-curl --request DELETE https://example-store.com/wp-json/wc/store/v1/cart/items/e369853df766fa44e1ed0ff613f563bd
+curl --header "Cart-Token: $CART_TOKEN" --request DELETE "https://example-store.com/wp-json/wc/store/v1/cart/items/e369853df766fa44e1ed0ff613f563bd"
 ```

 ## Delete All Cart Items
@@ -390,7 +398,7 @@ DELETE /cart/items/
 There are no extra parameters needed to use this endpoint.

 ```sh
-curl --request DELETE https://example-store.com/wp-json/wc/store/v1/cart/items
+curl --header "Cart-Token: $CART_TOKEN" --request DELETE "https://example-store.com/wp-json/wc/store/v1/cart/items"
 ```

 **Example response:**
diff --git a/plugins/woocommerce/changelog/woodocs-4143-4145-1122-developer-docs b/plugins/woocommerce/changelog/woodocs-4143-4145-1122-developer-docs
new file mode 100644
index 00000000000..bb0caa6184b
--- /dev/null
+++ b/plugins/woocommerce/changelog/woodocs-4143-4145-1122-developer-docs
@@ -0,0 +1,3 @@
+Significance: patch
+Type: dev
+Comment: Document WooCommerce 11.2.2 REST API authentication and Store API cart item changes.