woocommerce-store-api

Design and implement WooCommerce Store API routes, schemas, and authentication patterns.

10.5k|10.7k|Updated Aug 9, 2011
One-click install
npx skills add https://github.com/woocommerce/woocommerce --skill woocommerce-store-api
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: woocommerce-store-api
Source: https://github.com/woocommerce/woocommerce/tree/main/.ai/skills/woocommerce-store-api
Command: npx skills add https://github.com/woocommerce/woocommerce --skill woocommerce-store-api

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Adding or modifying endpoints under the WooCommerce Store API (/wc/store/v1/*) involves subtle conventions around authentication, schema contracts, variation reconciliation, and idempotency that are easy to get wrong, leading to CSRF vulnerabilities, N+1 query problems, and broken client integrations.

Core Features & Use Cases

  • Authentication guidance: Choose between AbstractRoute and AbstractCartRoute, enforce nonces correctly, and write conventional permission_callback closures.
  • Schema and REST conventions: Keep schemas as the single source of truth, apply correct status codes, design collection vs action routes, and build idempotent storage keys.
  • Variation handling and performance: Reconcile variation attributes server-side and apply cache priming to avoid N+1 queries in collection responses.
  • Use Case: When adding a new POST endpoint that lets shoppers save preferences to their cart, use this Skill to pick the right abstract route class, wire nonce validation, design the response schema, and write the required auth tests.

Quick Start

Use the woocommerce-store-api skill to help me add a new Store API endpoint for managing saved cart item notes with proper nonce handling and schema design.

Frequently Asked Questions about woocommerce-store-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new route to the WooCommerce Store API?

Register a route class under /wc/store/v1 extending the appropriate abstract base, declare its schema in get_properties(), and build responses inside get_item_response(). Follow the cart routes like CartItems as canonical examples for POST, DELETE, and action-style endpoints.

Should my Store API route extend AbstractRoute or AbstractCartRoute?

Extend AbstractCartRoute for any route that mutates per-user state via cookie sessions, since it enforces nonce verification and cart-session loading. Use AbstractRoute only for read-only routes or routes with their own authentication model.

Why does my Store API route return 401 woocommerce_rest_missing_nonce?

State-changing routes extending AbstractCartRoute require a Nonce header verified against the wc_store_api action on non-GET requests without a Cart-Token. The client must echo back the fresh Nonce response header provided by the previous response.

How do I handle product variation attributes in Store API requests?

Derive canonical attributes from the variation product itself rather than trusting the client payload, following CartController::parse_variation_data(). Validate posted slugs against wc_get_product_variation_attributes() and throw RouteException with 400 for invalid or missing variation data.

How do I avoid N+1 queries in Store API collection responses?

Call _prime_post_caches() with the full list of product IDs before the per-item serialization loop, preferably inside the schema's get_item_response(). When rendering product images, run a second priming pass on thumbnail IDs with meta cache updates enabled.

Can I test Store API routes with Application Passwords?

Application Passwords authenticate the user but do not carry a cart session cookie, so they only work for routes that do not read WC()->cart. Routes depending on cart contents require cookie-based authentication with proper nonce headers.