Get all products from Woocommerce using REST API

Get all products from Woocommerce using REST API

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Get all products from Woocommerce using REST API

When querying the WooCommerce REST API to retrieve a catalog, the default behavior often feels restrictive. By default, pagination is set to return only 10 items per request. This is useful for building paginated lists in an admin dashboard or preventing excessive data transfer on slow connections. However, attempting to fetch the entire product database with a single request by passing ?filter[posts_per_page]=-1 frequently results in the server returning exactly 10 items instead of the full set.

This behavior is not a bug; it is a deliberate security and performance safeguard implemented in the WooCommerce REST API. The parameter posts_per_page=-1 tells the database layer to ignore pagination limits, but the API middleware intercepts this request and caps the result size at 10 unless specific conditions are met. If you simply copy that URL into Postman or a browser, you will see that limit enforced regardless of the value passed.

To bypass this restriction legitimately, you must address two distinct requirements: authentication and context. The WooCommerce REST API v2 enforces stricter security protocols than earlier versions. Without proper credentials, the endpoint /wp-json/wc/v2/products will not return all products, even if pagination is configured correctly. You need to include a valid Authorization header containing your consumer key and secret.

Authorization: Basic base64(Your_Consumer_Key:Your_Consumer_Secret)

However, there is a deeper architectural reason why the -1 flag fails without additional context. WooCommerce treats bulk data retrieval differently depending on whether the request originates from a user or an administrator. The default 10-item limit applies to non-admin users to prevent resource exhaustion and potential scraping attacks. To retrieve the full dataset in a single call, your authentication token must indicate that the request is coming from a role with elevated privileges.

If you are using consumer keys generated for a standard "WooCommerce" user account, you will still hit the 10-item cap even with valid headers. The API checks the role associated with the authenticated user. If that user does not have the administrator capability, the system enforces the limit. This is by design to protect your store's data from unauthorized bulk extraction.

There are two primary ways to resolve this:

  1. Generate Admin Keys: Create a new consumer key specifically for an administrator account. When you generate keys in WooCommerce > Settings > General > API access, select "All" scopes and ensure the user has administrative permissions. Once you use these keys in your Authorization header, the -1 flag will work as expected, returning every product record.
  2. Use the Admin REST API: Instead of using /wp-json/wc/v2/products, you can access the native WordPress REST API at /wp-json/wp/v2/posts?per_page=-1&post_type=product. This endpoint does not require WooCommerce-specific authentication headers if you are logged in as an administrator via cookie-based auth, but it requires managing WordPress session cookies or using a private key with the administrator role.

Handling Large Datasets

While fetching all products at once works for small catalogs, relying on posts_per_page=-1 creates a single massive JSON response. For stores with thousands of products, this approach introduces significant latency and memory overhead on both the server and the client. The API will return a list where every product is serialized into an associative array.

If you are building a robust application, consider implementing a cursor-based pagination strategy or accepting that posts_per_page limits might be necessary for production stability. You can still fetch all products by iterating through pages if you do not have admin keys, but this requires writing logic to handle the offset or using the page and per_page parameters sequentially.

Another consideration is the data volume. A single request returning thousands of objects can cause timeouts in environments with strict connection limits. If your goal is to export data for analysis or migration, it is often safer to use a dedicated export plugin rather than hacking the API pagination limits. Tools designed for bulk export handle database locking and temporary table creation more efficiently than direct API calls.

Ultimately, the inability to use posts_per_page=-1 without admin keys is a feature, not a flaw. It forces developers to implement proper authentication flows and consider the performance implications of data retrieval strategies. If you need full access, generate an admin key; if you only need a subset, respect the pagination limits to maintain API health.

Our network