skip to Main Content

I am using the Woocommerce REST API library @woocommerce/woocommerce-rest-api in my React native e-commerce app. I have also tried out the library https://github.com/JamesUgbanu/react-native-woocommerce-api. I am testing this on localhost:8080.

In AndroidManifest.xml, the android:usesCleartextTraffic attribute is set to "true".

Both the aforementioned libraries generate the URL as such

http://localhost:8080/wp-json/wc/v3/products?oauth_consumer_key=ck_d1e9172ffce8f4016a3ae9b1ee8bce8b7a4c6365&oauth_nonce=ajJA9q13HYyZJU2TRMIqaeYU3vq1I1DP&oauth_signature_method=HMAC-SHA256&oauth_timestamp=1611684425&oauth_version=1.0&oauth_signature=MEh5Rb72foVJtC6k8E9GsV6DeExMF%2BDyKK0CcRC4EeM%3D

The API call from the React Native app shows a status code of 0 and no response.

When I copy the generated URL and run the API from the browser (simply pasting the URL into the address bar), the call is successful and the response contains the expected data.

When I cURL from the terminal though, it throws 401 error.

curl -H "accept:application/json" -H "user-agent:WooCommerce REST API - JS Client/1.0.1" http://localhost:8080/wp-json/wc/v3/products?oauth_consumer_key=ck_d1e9172ffce8f4016a3ae9b1ee8bce8b7a4c6365&oauth_nonce=ajJA9q13HYyZJU2TRMIqaeYU3vq1I1DP&oauth_signature_method=HMAC-SHA256&oauth_timestamp=1611684425&oauth_version=1.0&oauth_signature=MEh5Rb72foVJtC6k8E9GsV6DeExMF%2BDyKK0CcRC4EeM%3D


{"code":"woocommerce_rest_authentication_missing_parameter","message":"Missing OAuth parameters oauth_timestamp, oauth_nonce, oauth_signature, oauth_signature_method","data":{"status":401}}

What’s going on? Why such varying responses from different sources? Above all, how do I get the response in the app?

2

Answers


  1. The Word ‘localhost’ is a reserved word for android. Replace localhost with your pc’s ip address and it should work fine on android emulator.

    Login or Signup to reply.
  2. For those who are facing similar issues, do check if you are making your request on http or https. Add s if it is http.

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