Back

WooCommerce API Essential Guide

Aug 11, 20246 minute read

What type of API does WooCommerce provide?

WooCommerce primarily uses a REST API. Here are the key points about WooCommerce's API:

Type of API

  • WooCommerce uses a REST API as its primary API type.

Key features

  • The WooCommerce REST API is fully integrated with the WordPress REST API.
  • It allows creating, reading, updating, and deleting WooCommerce data using JSON format and standard HTTP verbs.
  • The current API version is v3, which is available in WooCommerce 3.5.x and later.

Authentication

  • The API supports authentication over HTTPS using HTTP Basic Auth.
  • It also allows authentication using WordPress REST API authentication plugins or methods.

Official libraries

  • WooCommerce provides official client libraries for various programming languages, including JavaScript, PHP, Python, and Ruby.

Webhooks

  • The API includes webhook functionality for real-time event notifications.

Requirements

  • WooCommerce 3.5+ and WordPress 4.4+ are required to use the latest version of the REST API.
  • Pretty permalinks must be enabled in WordPress settings.

Legacy API

  • WooCommerce also has a legacy REST API, which is separate from the WordPress REST API.
  • The legacy API will be moved to a dedicated extension in WooCommerce 9.0.

Best practices

  • HTTPS is recommended for API access where possible.
  • Developers should refer to the official WooCommerce REST API documentation for detailed information on endpoints and usage.

In summary, while WooCommerce primarily uses a REST API, it does not offer GraphQL or SOAP APIs as built-in options. The REST API provides a comprehensive set of features for interacting with WooCommerce data programmatically.

Does the WooCommerce API have webhooks?

Yes, the official WooCommerce API does have webhooks. Here are the key points about WooCommerce webhooks:

Webhook Availability

  • WooCommerce has built-in support for webhooks, which were introduced in WooCommerce 2.2.

Types of Events You Can Subscribe To

WooCommerce webhooks can be triggered by various events, including:

  • Order events: Created, updated, deleted
  • Product events: Created, updated, deleted
  • Customer events: Created, updated, deleted
  • Coupon events: Created, updated, deleted
  • Cart events: e.g., when a product is added to the cart (using the woocommerce_add_to_cart action)

Creating Webhooks

You can create webhooks through the WooCommerce admin interface:

  1. Go to WooCommerce > Settings > Advanced > Webhooks
  2. Click "Create a new webhook" or "Add webhook"
  3. Fill in the webhook details:
    • Name
    • Status (Active, Paused, or Disabled)
    • Topic (the event that triggers the webhook)
    • Delivery URL
    • Secret key

Custom Webhooks

  • You can create custom webhooks for more specific events using the woocommerce_webhook_topic_hooks filter.
  • This allows for advanced customization of webhook triggers.

Webhook Management

  • Webhooks can be edited, deleted, and managed through the WooCommerce admin interface.
  • Webhook logs are available for debugging and monitoring purposes.

Best Practices

  • Use webhooks for real-time automation and integration with external systems.
  • Implement proper error handling and retry mechanisms, as webhooks are disabled after 5 failed attempts by default.
  • Utilize the woocommerce_max_webhook_delivery_failures filter to customize the number of retry attempts.

WooCommerce webhooks provide a powerful way to integrate your store with external systems and automate processes based on various store events. They offer flexibility and real-time responsiveness, making them a valuable tool for enhancing your WooCommerce store's functionality and efficiency.

Rate Limits and other limitations

Here are the key points about the API rate limits for the WooCommerce API:

Default Limit

  • By default, the WooCommerce REST API is limited to up to 100 objects to be created, updated or deleted in a single request [1][3].

Store API Rate Limiting

  • WooCommerce introduced rate limiting for the Store API starting with WooCommerce Blocks 8.9.0 [2].

  • This rate limiting is opt-in and disabled by default [2].

  • When enabled, it protects the block-based checkout process and all requests to the /cart and /product endpoints [2].

Configuring Rate Limiting

  • Developers can enable and configure rate limiting using the woocommerce_store_api_rate_limit_options filter [2].

  • The default configuration when enabled is:

    • 25 requests allowed
    • Within a 10 second timeframe
    • Per user ID (for logged in users) or IP address (for guests) [2]
  • Example configuration:

add_filter( 'woocommerce_store_api_rate_limit_options', function() { return [ 'enabled' => true, 'proxy_support' => false, 'limit' => 25, 'seconds' => 10, ]; } );

Key Considerations

  • The 100 object limit for batch operations is set to maintain server performance and prevent timeouts [1].

  • Modifying this limit directly in the plugin code is not recommended as it can lead to issues and will be lost on updates [1].

  • For operations requiring more than 100 objects, it's recommended to use multiple API requests or consult with a developer for a custom solution [1].

  • The Store API rate limiting feature is separate from the core WooCommerce REST API limits [2].

Best Practices

  • Use pagination and multiple requests for large datasets instead of trying to bypass the 100 object limit.

  • Enable rate limiting on the Store API for high-traffic stores to protect against potential abuse.

  • Consider implementing custom rate limiting for other WooCommerce REST API endpoints if needed for your specific use case.

Latest API Version

Here is a summary of the most recent version of the WooCommerce API based on the search results:

The most recent version of the WooCommerce API is v3 (wc/v3).

Key points:

  • WooCommerce v3.5.x and later uses API version v3 [1]

  • The current WP REST API integration version is v3, which takes a first-order position in endpoints [1]

  • When setting up API clients, the version should be specified as "wc/v3" [1]

  • WooCommerce 9.0 was released on June 18, 2024 and is the latest major version, but it does not indicate a new API version [3]

  • The v3 API has been the current version for several years now, with no indication of a newer version being released [1][3]

Best practices:

  • Use the v3 API for new integrations and development [1]

  • Specify "wc/v3" as the version when setting up API clients [1]

  • Consider migrating away from the legacy API versions (v1, v2) as they have been deprecated [5]

In summary, the most recent and current version of the WooCommerce API is v3 (wc/v3), which has been the stable version for several years now. When integrating with WooCommerce, it's recommended to use this latest v3 API version.

How to get a WooCommerce developer account and API Keys?

Here's how to get a developer account for WooCommerce to create an API integration:

Generating API Keys:

  1. Go to WooCommerce > Settings > Advanced > REST API in your WordPress admin.
  2. Click "Add Key".
  3. Select the WordPress user you want to generate the key for.
  4. Choose the level of access for the API key (Read, Write, or Read/Write).
  5. Click "Generate API Key".
  6. You'll now see the Consumer Key and Consumer Secret, which you'll use to authenticate API requests.

Using the API:

  • You can now use these API keys to make requests to the WooCommerce REST API endpoints.
  • There are official libraries available for PHP, Python, Ruby, and Node.js to help you interact with the API.

Best Practices:

  1. Always use HTTPS for secure communication when making API requests.
  2. Store your API keys securely and never expose them publicly.
  3. Use the appropriate access level (Read, Write, or Read/Write) based on your integration needs.
  4. Familiarize yourself with the API documentation for detailed endpoint information and usage.

What can you do with the WooCommerce API?

Based on the search results provided, here is a list of data models you can interact with using the WooCommerce API, along with what is possible for each:

Products

  • Create, read, update, and delete products [1][4]
  • Manage product attributes [4]
  • Handle variable products [3]

Orders

  • Create, read, update, and delete orders [1][4]
  • Retrieve order details, including customer information, line items, and totals [3]

Customers

  • Create, read, update, and delete customer data [1][4]

Coupons

  • Create, read, update, and delete coupons [1][4]

Subscriptions (if using WooCommerce Subscriptions)

  • Manage subscription products [3]
  • Retrieve subscription details, including order IDs and subscription IDs [3]

Shipping Zones

  • Manage shipping zones and methods [5]

Product Categories

  • Create, read, update, and delete product categories [1][4]

Product Tags

  • Manage product tags [1][4]

Product Reviews

  • Retrieve and manage product reviews [1][4]

Refunds

  • Process and manage refunds for orders [1][4]

Reports

  • Access various reports on sales, customers, and products [1][4]

Settings

  • Retrieve and update WooCommerce store settings [1][4]

Webhooks

  • Create, manage, and delete webhooks for real-time event notifications [1][4]

Tax Rates

  • Manage tax rates and classes [1][4]

Payment Gateways

  • Retrieve information about available payment gateways [1][4]

For each of these data models, the WooCommerce API generally allows you to:

  1. Retrieve lists of items (GET requests)
  2. Retrieve individual items by ID (GET requests)
  3. Create new items (POST requests)
  4. Update existing items (PUT or PATCH requests)
  5. Delete items (DELETE requests)

The specific operations available may vary depending on the data model and the version of the API you're using. It's always best to consult the official WooCommerce REST API documentation for the most up-to-date and detailed information on each endpoint and its capabilities.