Comments (4)
Hi @Myerden,
Can I have look at the response you got?
from react-native-woocommerce-api.
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:
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.
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.
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)
- Won't work over http
- While trying to resolve module `react-native-woocommerce-api`
- Syntax Error "Identifier 'WooCommerceAPI' has already been declared"
- how to use the query params in react-native-woocommerce-api? HOT 2
- Use WpAPI HOT 1
- Issue with params and subscriptions HOT 10
- CORS Error HOT 1
- .catch never catching
- undefined is not an object (evaluating '_WooAPI.WooAPI.get') HOT 1
- i am getting error : woocommerce_rest_authentication_error HOT 1
- App device CORS Error HOT 3
- Login API HOT 1
- woocommerce_rest_authentication_error HOT 1
- Invalid signature - provided signature does not match HOT 3
- Custom headers
- TypeScript HOT 3
- How can I add query string params to the request? HOT 1
- woocommerce_rest_authentication_error HOT 19
- Error catching issue HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-woocommerce-api.