woocommerce axios react

Question

I don’t understand why my request to WooCommerce API doesn’t work.
My usage on react App via axios:

First try:

return axios.get( 'http://domain/wp-json/wc/v3/products?featured=true',
  {
      headers: {
        'consumer_key': 'ck_xxx',
        'consumer_secret': 'cs_xxx',
        'key_id': 111,
        'key_permissions': 'read_write',
        'user_id': 111,
  }
)

Second one:

return axios( {
  url: 'http://domain/wp-json/wc/v3/products?featured=true',
    headers: {
      'origin': 'http;//localhost:3000',
      'consumer_key': 'ck_x',
      'consumer_secret': 'cs_x',
      'key_id': 111,
      'key_permissions': 'read_write',
      'user_id': 111,
      },
      method: 'GET',
    }
} )

And I get CORS error. But using Insomnia software I create a GET request to http://domain/wp-json/wc/v3/products?featured=true with Basic Auth tab:

USERNAME ck_x
PASSWORD cs_x

therefore response status is 200 OK.

I appreciate to understand what I’m doing wrong in axios inside my React App.

0
Enrique Rene 2 years 2020-10-24T14:10:45-05:00 0 Answers 19 views 0

Leave an answer

Browse
Browse