Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Woocommerce api get all products
    WooCommerce REST API fetch products pagination API methods JavaScript PHP Python React


Woocommerce api get all products


To get all products from WooCommerce using the REST API, you can use the following methods:

1. Using the `per_page` Parameter

bash
https://squatwolf.com/wp-json/wc/v2/products?per_page=100

This method fetches the first 100 products. You can adjust the number to fetch more products.

2. Using the `filter[posts_per_page]` Parameter (Legacy Method)

bash
https://squatwolf.com/wp-json/wc/v2/products?filter[posts_per_page]=-1

This method fetches all products, but it may not work for large product lists due to server limitations.

3. Looping Through Pages

bash
https://squatwolf.com/wp-json/wc/v2/products?page=1
https://squatwolf.com/wp-json/wc/v2/products?page=2
...

This method fetches products in batches by looping through the pages. You can use JavaScript or other programming languages to automate this process.

4. Using the `category` Parameter

bash
https://squatwolf.com/wp-json/wc/v3/products?category=ID

This method fetches all products in a specific category. Replace `ID` with the ID of the category you want to fetch products from.

5. Using the WooCommerce REST API Client Library

php
$wc_api = new WC_API_Client($consumer_key, $consumer_secret, $store_url);
print_r($wc_api->get_products());

This method uses the WooCommerce REST API Client Library to fetch all products. You need to install the library and configure it with your API credentials.

6. Using the `filter[limit]` Parameter

php
$wc_api->get_products(array('filter[limit]' => 500));

This method fetches a specific number of products. You can adjust the number to fetch more products.

7. Using the `posts_per_page` Parameter in JavaScript

javascript
fetch('https://squatwolf.com/wp-json/wc/v2/products?per_page=100')
  .then(response => response.json())
  .then(data => console.log(data));

This method fetches the first 100 products using JavaScript and the Fetch API.

8. Using the `woocommerce-rest-api` Library in JavaScript

javascript
import { getProducts } from '@woocommerce/woocommerce-rest-api';

getProducts({
  url: 'https://squatwolf.com/wp-json/wc/v2/products',
  params: {
    per_page: 100,
  },
})
  .then((response) => console.log(response.data));

This method fetches the first 100 products using the `woocommerce-rest-api` library in JavaScript.

9. Using the `woocommerce-rest-api` Library in Python

python
import requests

response = requests.get(
    'https://squatwolf.com/wp-json/wc/v2/products',
    params={'per_page': 100},
)

data = response.json()
print(data)

This method fetches the first 100 products using the `requests` library in Python.

10. Using the `woocommerce-rest-api` Library in React

javascript
import React, { useState, useEffect } from 'react';
import { getProducts } from '@woocommerce/woocommerce-rest-api';

const App = () => {
  const [products, setProducts] = useState([]);

  useEffect(() => {
    getProducts({
      url: 'https://squatwolf.com/wp-json/wc/v2/products',
      params: {
        per_page: 100,
      },
    })
      .then((response) => setProducts(response.data));
  }, []);

  return (
    <div>
      {products.map((product) => (
        <div key={product.id}>
          {product.name}
        </div>
      ))}
    </div>
  );
};

This method fetches the first 100 products using the `woocommerce-rest-api` library in a React application.

These methods can be used to fetch all products from WooCommerce using the REST API.

Citations:
[1] https://stackoverflow.com/questions/48476534/get-all-products-from-woocommerce-using-rest-api
[2] https://wordpress.org/support/topic/wc-rest-api-get-products-list-by-category-slug/
[3] https://github.com/kloon/WooCommerce-REST-API-Client-Library/issues/27
[4] https://www.youtube.com/watch?v=YJj2edx0ZFs
[5] https://www.nexcess.net/blog/woocommerce-api/

The maximum number of products that can be fetched in one API call from WooCommerce is 100 per page. This is due to the default pagination limit set by WooCommerce. To fetch more products, you need to loop through the pages and make multiple API calls. Here are some methods to achieve this:

1. Using the `per_page` Parameter

bash
https://squatwolf.com/wp-json/wc/v2/products?per_page=100

This method fetches the first 100 products. You can adjust the number to fetch more products.

2. Using the `filter[posts_per_page]` Parameter (Legacy Method)

bash
https://squatwolf.com/wp-json/wc/v2/products?filter[posts_per_page]=-1

This method fetches all products, but it may not work for large product lists due to server limitations.

3. Looping Through Pages

bash
https://squatwolf.com/wp-json/wc/v2/products?page=1
https://squatwolf.com/wp-json/wc/v2/products?page=2
...

This method fetches products in batches by looping through the pages. You can use JavaScript or other programming languages to automate this process.

4. Using the WooCommerce REST API Client Library

php
$wc_api = new WC_API_Client($consumer_key, $consumer_secret, $store_url);
print_r($wc_api->get_products());

This method uses the WooCommerce REST API Client Library to fetch all products. You need to install the library and configure it with your API credentials.

5. Using the `filter[limit]` Parameter

php
$wc_api->get_products(array('filter[limit]' => 500));

This method fetches a specific number of products. You can adjust the number to fetch more products.

6. Using the `woocommerce-rest-api` Library in JavaScript

javascript
fetch('https://squatwolf.com/wp-json/wc/v2/products?per_page=100')
  .then(response => response.json())
  .then(data => console.log(data));

This method fetches the first 100 products using JavaScript and the Fetch API.

7. Using the `woocommerce-rest-api` Library in Python

python
import requests

response = requests.get(
    'https://squatwolf.com/wp-json/wc/v2/products',
    params={'per_page': 100},
)

data = response.json()
print(data)

This method fetches the first 100 products using the `requests` library in Python.

8. Using the `woocommerce-rest-api` Library in React

javascript
import React, { useState, useEffect } from 'react';
import { getProducts } from '@woocommerce/woocommerce-rest-api';

const App = () => {
  const [products, setProducts] = useState([]);

  useEffect(() => {
    getProducts({
      url: 'https://squatwolf.com/wp-json/wc/v2/products',
      params: {
        per_page: 100,
      },
    })
      .then((response) => setProducts(response.data));
  }, []);

  return (
    <div>
      {products.map((product) => (
        <div key={product.id}>
          {product.name}
        </div>
      ))}
    </div>
  );
};

This method fetches the first 100 products using the `woocommerce-rest-api` library in a React application.

These methods can be used to fetch all products from WooCommerce using the REST API.

Citations:
[1] https://forum.bubble.io/t/woocommerce-api-get-product-list-limited-to-100-products-per-page/155618
[2] https://wordpress.stackexchange.com/questions/358849/getting-all-woocommerce-products-from-rest-api-call-in-plugin
[3] https://github.com/kloon/WooCommerce-REST-API-Client-Library/issues/27
[4] https://www.make.com/en/help/app/woocommerce
[5] https://stackoverflow.com/questions/48476534/get-all-products-from-woocommerce-using-rest-api