WooCommerce REST API consumer key missing dedicated read‑only order notes scope
0 reputation · 06 Dec 2024, 02:31 UTC
0 reputation · 06 Dec 2024, 02:31 UTC
Administrators aim to issue a WooCommerce REST API consumer key that can retrieve order notes but cannot modify any order data. Currently the API grants access to order notes through the same 'shop_order' read capability that also underpins the edit_shop_orders permission, so a key intended for read‑only note viewing inadvertently allows write operations when the associated user holds edit_shop_orders. There is no built‑in way to split these permissions, and reliance on role‑editor plugins or dedicated users remains a workaround. It is unclear whether the forthcoming REST API v3 roadmap will introduce an explicit read‑only scope for order notes that would resolve this ambiguity.
Is there a method to achieve true read‑only order‑note access via consumer key without granting edit_shop_orders? Does the planned API v3 include a dedicated read‑only order notes permission? How can a store owner verify that a consumer key’s privileges are limited to order notes only in the present version?
31275 reputation · 06 Dec 2024, 13:02 UTC
Currently, there is no native method within the WooCommerce REST API to grant a consumer key read-only access to order notes without granting broader order edit capabilities. The API architecture ties order note retrieval to the shop_order capability, which is bundled with edit_shop_orders at the WordPress role level.
The core issue arises because consumer keys inherit the permissions of the WordPress user they are associated with. If a user has a role that allows editing orders, the associated consumer key can perform POST, PUT, PATCH, and DELETE operations on order endpoints. There is no specific read_order_notes scope to decouple this action from the order object itself.
There is no confirmed information in the WooCommerce REST API v3 roadmap regarding a dedicated, read-only permission for order notes. Until such an update is released, administrators must rely on external workarounds to enforce this restriction.
To verify if a consumer key is truly limited to read-only access in your current environment, follow these steps using a custom WordPress role:
read capability and specifically lacks edit_shop_orders.curl to attempt to update an order note:
curl -X POST "https://your-store.com/wp-json/wc/v3/orders/123"
-H "Authorization: Basic ck_KEY:ckk_SECRET" \\n -H "Content-Type: application/json" \\n -d '{"notes": [{"note": "Test note"}]}'
If the API returns a 403 Forbidden, the key is successfully restricted to read-only. If the note updates, the user role still possesses too much privilege.
If you require the key to see only notes and block all other order data, you must implement a custom filter in your functions.php that hooks into the REST_API_init action to strip sensitive fields from the order response for specific roles.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.