in

WooCommerce REST API Pagination: Easy Examples to Get You Started

Learn how WooCommerce REST API pagination works, from choosing `per_page` to moving through results with `page`. This WooCommerce REST API pagination example shows how to read response headers, fetch products one page at a time, and handle larger datasets with confidence.

When your WooCommerce store has lots of products, orders, or customers, retrieving everything in one request isn’t practical. Pagination lets you fetch results in smaller, manageable batches, helping your integrations work more smoothly.

This guide explains WooCommerce REST API pagination with clear examples you can adapt to your project. You’ll see how to request specific pages, control how many results each response contains, and move through records efficiently. Whether you’re building your first integration or refining an existing one, this WooCommerce REST API pagination example will help you get started with confidence.

How WooCommerce REST API Pagination Works

Once you know which endpoint to call, the next question is how to move through its results without missing records or requesting more than you need. WooCommerce uses page numbers and page sizes to split a collection into separate responses, with headers that help you track your progress.

Start with the two query parameters that control which slice of the collection you receive. The example below requests the second batch of 25 products.

Page numbers, page sizes, and response headers

Use perpage to set the number of records in a response and page to select the batch. For example, /wp-json/wc/v3/products?perpage=25&page=2 requests products 26–50, assuming the results haven’t changed between requests. If you omit these parameters, the API applies its defaults.

To find out how many requests are needed, check the response headers. WooCommerce returns X-WP-Total with the total matching records and X-WP-TotalPages with the number of available pages. A client can use these values to stop when it reaches the final page rather than guessing.

  • perpage sets the batch size.
  • page identifies the batch to retrieve.
  • X-WP-TotalPages indicates when pagination is complete.

Choosing a batch size is a balance: larger responses mean fewer requests, while smaller ones can be easier to process. Consider the data your integration handles and the resources available to it.

How to choose a page size

WooCommerce supports up to 100 records per page. A page size of 100 can suit a reliable server-to-server sync, while a smaller value—such as 20 or 25—may be more manageable when records contain substantial data or your client has limited memory.

For a WooCommerce REST API pagination example, try ?perpage=25&page=1, then request pages 2, 3, and onward until you reach the total page count. Test the size with real responses; the best setting depends on payload size, network conditions, and how quickly your integration can process each batch.

Even with a suitable batch size, pagination affects how many API calls your workflow makes. Keeping the endpoint’s maximum in mind helps you plan a steady, predictable sync.

What pagination limits mean for your requests

The perpage limit applies to each response, not to the total number of records you can retrieve. If there are 240 matching products and you request 100 per page, you’ll need three requests. Build your loop around X-WP-TotalPages so it can adapt when the collection grows or shrinks.

For large or frequently changing collections, avoid assuming every page remains identical throughout a long sync: new records may be added while you work. Where practical, use a consistent sort order and save a checkpoint after each successful batch, making retries easier and reducing the chance of duplicate processing.

A WooCommerce REST API pagination example

Want to see how the pieces fit together in a real request? This walkthrough follows a product collection from the first page to the last, then shows how to use the response headers to decide when to stop.

First, let’s make a request that retrieves a single batch. The same pattern works with other collection endpoints, such as orders or customers.

Fetching products one page at a time

Send a request to the products endpoint and process the records it returns before moving on. For example, with authentication already configured, you can use curl to request the first 25 products:

curl -i "https://example.com/wp-json/wc/v3/products?perpage=25&page=1" 
  -u "consumerkey:consumersecret"

To fetch the next batch, change page=1 to page=2. Continue in sequence, saving or processing each response before requesting another. This makes the approach useful for scheduled imports, where you can record the last successfully handled page and resume after a temporary error.

Once the first request is working, the query parameters let you adjust the size and position of each batch. Keep the values explicit so the behavior is easy to understand and troubleshoot.

Using perpage and page parameters

Here’s a compact WooCommerce REST API pagination example for requesting the third batch of 40 products:

GET /wp-json/wc/v3/products?perpage=40&page=3

That request asks for records in the third slice of the matching collection—not necessarily products with IDs 81–120, since IDs can have gaps and the endpoint’s sort order determines which items appear. If your workflow depends on repeatable results, choose a consistent ordering where the endpoint supports it, and keep filters identical across page requests.

  • perpage=40 requests up to 40 products per response.
  • page=3 selects the third response batch.
  • Use the same filters and ordering for each request in a run.

Rather than hard-coding a final page, let the server’s headers tell your client how much data matched. This is especially helpful when the catalog changes over time.

Reading pagination metadata from response headers

The -i option in the earlier curl command includes response headers. Look for X-WP-Total and X-WP-TotalPages: the first reports the total number of matching records, while the second gives the number of batches for the selected page size.

For example, if the headers report X-WP-Total: 73 and X-WP-TotalPages: 3, request pages 1 through 3, then stop. Your client should read these values from each response and handle an empty or failed response separately, so a temporary issue isn’t mistaken for the end of the collection.

Practical Pagination Patterns and Troubleshooting

Getting the right batches is only half the job; your integration also needs to process them reliably. A few practical habits can help prevent missed records, unnecessary requests, and avoidable interruptions.

A repeatable loop makes it easier to handle collections of any size without manually changing the page number. The example below shows how to use the page count from the response while keeping each batch manageable.

Looping through all results

Request page 1, process its records, then continue until you reach the last page. In Python, a WooCommerce REST API pagination example might look like this:

page = 1
while True:
    response = requests.get(
        "https://example.com/wp-json/wc/v3/products",
        params={"perpage": 100, "page": page},
        auth=(consumerkey, consumersecret),
        timeout=30
    )
    response.raiseforstatus()
    products = response.json()
    process(products)
    totalpages = int(response.headers["X-WP-TotalPages"])
    if page >= totalpages:
        break
    page += 1

Keep filters and sorting consistent across requests, and make processing safe to retry. For example, saving a product by its ID with an update-or-insert operation helps avoid duplicate work if a sync stops and starts again.

For a small catalog, collecting every response in memory may seem convenient. As the dataset grows, processing each batch as it arrives is usually safer and lets your integration make progress even if a later request fails.

Handling large datasets efficiently

Use a page size that balances request overhead with the memory and processing time available to your application. The maximum is 100 records per page, but that may not be the best choice if each product includes many variations or extensive metadata.

For longer jobs, consider these safeguards:

  • Process and save each batch before requesting the next one.
  • Store a checkpoint, such as the last successfully processed page or record ID.
  • Set a reasonable timeout and retry temporary network or server failures with a brief, increasing delay.
  • Run a follow-up sync to catch records added or changed while the initial import was underway.

When a run behaves unexpectedly, check the response itself before changing your loop. The HTTP status and response body often point directly to the cause.

Common pagination errors and how to fix them

A 400 response can indicate an invalid parameter or a page size above the allowed maximum; verify the endpoint and keep per_page at 100 or lower. A 401 or 403 response usually calls for checking credentials, permissions, and the store URL.

An empty response can simply mean the requested page is beyond the available results, especially if the collection changed during the sync. For 429 or 5xx errors, pause and retry with backoff rather than rapidly repeating the same request. Log the page number, status code, and error message so you can resume or diagnose the run without starting over.

Make WooCommerce Pagination Work for Your Integration

WooCommerce REST API pagination gives you a practical way to retrieve large collections without overwhelming your application or relying on a single oversized request. With a clear page-by-page approach, sensible batch sizes, and response metadata to guide the process, you can build integrations that scale as your store grows.

Keep requests consistent, process results as they arrive, and plan for changes or temporary errors with checkpoints and retries. Start with the WooCommerce REST API pagination example in this guide, adapt it to your endpoint and workload, and you’ll be well on your way to a more dependable data sync.

Leave a Reply

Your email address will not be published. Required fields are marked *

      Written by Maeve Rodriguez

      Maeve is a Business Content Writer and Front-End Developer. She's a versatile professional with a talent for captivating writing and eye-catching design.