WooCommerce REST API Legacy Documentation

repository·trunk·Indexed 41 days ago

https://github.com/woocommerce/woocommerce-rest-api-docs

Legacy documentation for the WooCommerce REST API, including details for v1 and v2. Covers endpoints for coupons, customers, orders, products, and sales reports, as well as configuration for JSON/XML response formats and JSON-P. Note: This documentation is deprecated in favor of the official WooCommerce developer portal.

Tokens
173.1K
Snippets
408
Records
628
Agent score
50%

What's inside WooCommerce REST API

  1. Use Webhook Topics to trigger events

    trunk

    A topic is a combination of a resource and an event. When you create a webhook using a core topic name, the appropriate hooks are automatically added.

    Core Topics:

    • Coupons: coupon.created, coupon.updated, coupon.deleted
    • Customers: customer.created, customer.updated, customer.deleted
    • Orders: order.created, order.updated, order.deleted
    • Products: product.created, product.updated, product.deleted

    Custom Topics: You can use custom topics that map to a single hook name. For example, a topic named action.woocommerce_add_to_cart will trigger on that specific event. Custom topics pass the first hook argument directly into the payload (e.g., the cart_item_key would be included).

  2. Handle API pagination and Link headers

    trunk

    Requests returning multiple items are paginated. By default, 10 items are returned per page (configurable via the site's posts_per_page option).

    Pagination Controls:

    • ?filter[limit]=N: Specify items per page.
    • ?page=N: Specify the page number (1-based; omitting returns the first page).
    • ?filter[offset]=N: Specify the offset from the first resource.

    Metadata and Navigation:

    • HTTP Headers: The total number of resources is provided in X-WC-Total and the total pages in X-WC-TotalPages.
    • Link Header: Pagination URLs are provided in the standard RFC 5988 Link header. It is recommended to use these provided URLs rather than constructing your own. Supported rel values include:
      • next: URL for the immediate next page.
      • last: URL for the last page.
      • first: URL for the first page.
      • prev: URL for the immediate previous page.
    Link: <https://www.example.com/wc-api/v1/products?page=2>; rel="next",
    <https://www.example.com/wc-api/v1/products?page=3>; rel="last"
  3. Understand the Index JSON response structure

    trunk

    The Index response contains a store object with the following primary sections:

    • URL: The base URL of the store.
    • description: The store description.
    • meta: Configuration settings such as currency, timezone, tax_included, and weight_unit.
    • routes: A map of available API endpoints. Each route entry includes:
      • meta: Metadata for the route (e.g., self link).
      • supports: An array of supported HTTP methods (e.g., GET, POST, PUT, DELETE).
      • accepts_data: A boolean indicating if the endpoint accepts data payloads.
    • wc_version: The version of WooCommerce running on the store.
    {
        "store": {
            "URL": "http://example.com",
            "description": "",
            "meta": {
                "currency": "USD",
                "timezone": "America/Sao_Paulo"
                // ... other meta fields
            },
            "routes": {
                "/products": {
                    "accepts_data": true,
                    "meta": {
                        "self": "http://example.com/wc-api/v2/products"
                    },
                    "supports": ["HEAD", "GET", "POST"]
                }
                // ... other routes
            },
            "wc_version": "2.3.13"
        }
    }