woocommerce / woocommerce-rest-api-js-lib

New JavaScript library for WooCommerce REST API
https://www.npmjs.com/package/@woocommerce/woocommerce-rest-api
MIT License
273 stars 76 forks source link

param query per_page not working #99

Open dainq97 opened 3 years ago

dainq97 commented 3 years ago

I have a problem retrieving the products list, i want to return 20 item for request get products. I tried

const WooCommerceRestApi = require("@woocommerce/woocommerce-rest-api").default;

const api = new WooCommerceRestApi({
  url: "http://myurl.com",
  consumerKey: "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  consumerSecret: "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  version: "wc/v3"
});

api.get("products", {
  per_page: 20
})
  .then((response) => {
       console.log(response.data.length);
  })
  .catch((error) => {
    console.log("Response Data:", error.response.data);
  })
  .finally(() => {
    // Always executed.
  });

but the request doesn't seem to receive per_page=20, it return default 10 items can anyone help me to solve this problem? many thanks

joshpsawyer commented 3 years ago

Experiencing the same issue, but page param doesn't work for me either.

Actually, my issue isn't related to this but to my host. I'm using WP Engine and something about the way they're caching seems to be dropping query parameters. Regardless, I tried the request through postman with the same issue, so it's not this package.

@quocdai-IT you should send the request in Postman or curl and see if the parameter's respected outside of this package. If not, it's something to do with your host / woocommerce itself.

Update: it was a plugin that was the culprit.