4

I want to get data from backend using woocommerce api, but for that I need to pass Consumer Key and Consumer Secret, I am using axios library, so how can I pass those parameters with them?

the parameters that i want to include are : enter image description here

The code that I have written is as follows:

axios.get('https://LINK', {
       headers: {
      "consumerKey": "KEY",
      "consumerSecret": "SECRET",
     }
})
  .then((res) => {
    console.dir(res);

  })
  .catch(error => {
    console.log(error);
  });
  }
Mrugesh
  • 4,381
  • 8
  • 42
  • 84
  • did you solve this, struggling with axios and woocommerce authentication as well, with pretty much the exact same use case, a react app on top of wordpress and woocommerce, for an interactive part of the store. – bigmadwolf Feb 06 '18 at 21:35
  • anyone here to help i need help on this too – Joel Jerushan Jun 18 '18 at 12:26
  • Have you found any solution? I have also some issue. I don't able to find how to pass this credential in axios. – Kishan Bharda Sep 28 '20 at 05:57

3 Answers3

0

Try to set params in header of request. In this way

axios.get('https://LINK', {
      headers: {
          "consumerKey": "KEY",
          "consumerSecret": "SECRET",
         }
    })
      .then((res) => {
        console.dir(res);

      })
      .catch(error => {
        console.log(error);
      });
  }
Denis Lisitskiy
  • 1,285
  • 11
  • 15
0

Hope this could help someone, check out this snippet, API.URL & END_POINT could be anything you want, embed your consumer_key & consumer_secret inside parameter URL that's it.

componentDidMount(){
    let set = this
    let param = API.URL + 'END_POINT?consumer_key=YOUR_KEY&consumer_secret+YOUR_SECRET';
    axios.get(param)
    .then(function (response) {
        // handle success
        console.log(response.data);
        set.setState({ list: response.data, })
    })
    .catch(function (error) {
        // handle error
        console.log("Error ", error);
    })
    .then(function () {
        // always executed
    });
}
Joel Jerushan
  • 645
  • 11
  • 21
0

You can add axios-oauth-1.0a dependency - npm (https://www.npmjs.com/package/axios-oauth-1.0a)

and then follow the documentation:

import addOAuthInterceptor from 'axios-oauth-1.0a';

// Create a client whose requests will be signed
const client = axios.create();

// Specify the OAuth options
const options = {
     algorithm: 'HMAC-SHA1',
     key: 'xxx',
     secret: 'yyy',


// Add interceptor that signs requests
addOAuthInterceptor(client, options);