Coder Social home page Coder Social logo

Comments (4)

JamesUgbanu avatar JamesUgbanu commented on August 24, 2024

Hi @Myerden,
Can I have look at the response you got?

from react-native-woocommerce-api.

Myerden avatar Myerden commented on August 24, 2024

My code:

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

var API = new WooCommerceAPI({
    url: 'https://example.com/',
    ssl: true,
    consumerKey: 'ck_******',
    consumerSecret: 'cs_******',
    wpAPI: true,
    version: 'wc/v3',
    queryStringAuth: true
});

getProducts() {
	API.get('products')
	.then(data => {
	  console.log('data: ' + data);
      this.setState({ products: data });
    })
    .catch(error => {
      console.log(error);
    });
}

I got product list as array:

image

image

I need to access response headers but the result is only response json.

This is looking related with this line of code.

from react-native-woocommerce-api.

JamesUgbanu avatar JamesUgbanu commented on August 24, 2024

Hi @Myerden

Update the latest version and query like this;

getProducts() {
	API.get('products', {header: true})
	.then(data => {
	  console.log('data: ' + data);
      this.setState({ products: data });
    })
    .catch(error => {
      console.log(error);
    });
}

Please, check it with and without header, lets see if we are getting the correct response.

Thanks

from react-native-woocommerce-api.

Myerden avatar Myerden commented on August 24, 2024

Hi @JamesUgbanu,
Thank you for your support, you saved me.

Here is some working examples; data returns only array of products.

getProducts() {
    API.get('products') // or -> API.get('products', {header: false})
	.then(data => {
	  console.log('data: ' + data); // returns array of products 
      this.setState({ products: data });
    })
    .catch(error => {
      console.log(error);
    });
}

if I set header: true, data returns header info and array of products.
Example usage should be like this;

getProducts() {
    API.get('products', {header: true})
	.then(data => {
	  console.log('headers: ' + data.header); // returns header info
	  console.log('data: ' + data.data); // returns array of products 
      this.setState({ products: data.data });
    })
    .catch(error => {
      console.log(error);
    });
}

or like this

getProducts() {
    API.get('products', {header: true})
	.then(({data, header})=> {
	  console.log('headers: ' + header); // returns header info
	  console.log('data: ' + data); // returns array of products 
      this.setState({ products: data });
    })
    .catch(error => {
      console.log(error);
    });
}

from react-native-woocommerce-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.