How to get more then 10

hi,
i have got step thet retrive data from woocomerce with node.js code
the problem is - the request default is with only 10 obcects.
how can i get the full list of products\orders ?

thanks a lot

image

Hi @yehoshua , WooCommerce allows you to pass a per_page parameter that should let you fetch a larger number of items. You can pass that parameter in the params section of the axios request:

return await require("@pipedreamhq/platform").axios(this, {
  url: `https://${auths.woocommerce.url}/wp-json/wc/v3/products`,
  auth: {
    username: `${auths.woocommerce.key}`,
    password: `${auths.woocommerce.secret}`,
  },
  params: {
    per_page: params.per_page,
  }
})

Copy this example workflow to give that a try.

You can also modify the code to iterate over pages of results, adding them to an array that you return when you’re done paginating. I don’t have a WooCommerce account to test with, so you might have to modify this slightly, but conceptually, something like this should work:

const axios = require("axios")
const products = []
let numPages;
let page = 1;  // see docs - pages are 1-indexed
do {
  const { data, headers } = await axios({
    url: `https://${auths.woocommerce.url}/wp-json/wc/v3/products`,
    auth: {
      username: `${auths.woocommerce.key}`,
      password: `${auths.woocommerce.secret}`,
    },
    params: {
      per_page: 100,
      page, 
    }
  })
  numPages = headers["X-WP-Total"] // see docs - total number of pages is returned in this header
  page += 1  // increment page on each run
  products.push(data)
})
} while (page <= numPages)

return products;