skip to Main Content

I am building an ecommerce mobile app with react native and woocommerce and i an facing this issue.. per_page doesn’t work

This is the code

import WooCommerceAPI from 'react-native-woocommerce-api';

const WooCommerce = new WooCommerceAPI({
  url: 'http://example.com/', // Your store URL
  ssl: false,
  consumerKey: 'ck_xxxxxxxxxxx', // Your consumer key
  consumerSecret: 'cs_xxxxxxxxxxx', // Your consumer secret
  wpAPI: true, // Enable the WP REST API integration
  version: 'wc/v3', // WooCommerce WP REST API version
  queryStringAuth: true
});

Then

  componentDidMount() {
    WooCommerce.get('products?per_page=50', {})
      .then(res => {
        this.setState({
          data: res,
          isLoading: false
        });

      })
      .catch(error => {
        console.log(error);
        this.setState({
          error,
          isLoading: true
        });
      });
  }

and then

    console.log(this.state.data);

and i got this in console

Object {
“code”: “woocommerce_rest_authentication_error”,
“data”: Object {
“status”: 401,
},
“message”: “Invalid signature – provided signature does not match.”,
}

If i write WooCommerce.get('products', {}) it gets 10 products as a max limit from woocommerce API but i need to get all products

3

Answers


  1. Chosen as BEST ANSWER

    Open react-native-woocommerce-api.js in node_modulesreact-native-woocommerce-apilib

    then goto line 195 (_getOAuth().authorize function) and change:

    params.qs = this._getOAuth().authorize({
      url: url,
      method: method
    });
    

    to

    params.qs = this._getOAuth().authorize({
      url: url + '?' + this.join(data, '&'),
      method: method
    });
    

  2.  WooCommerce.get('products?per_page=100&page=1', {}) // YOu can set a Variable in-place of 1 and index 100 is the limit
    

    Older API version

    https://Yoursite/wc-api/v3/products?filter[limit] =-1
    

    Hope this helps

    Login or Signup to reply.
  3.  WooCommerce.get('products', {per_page: 50})
      .then(res => {
        this.setState({
          data: res,
          isLoading: false
        });
    
      })
      .catch(error => {
        console.log(error);
        this.setState({
          error,
          isLoading: true
        });
      });
    

    this should work!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search