1

I am using react as a front end for a wordpress site. From a form i am trying to POST data to wordpress using axios and the wp-api. Below is how I am trying to do this, but I keep getting:

code: "rest_cannot_create", message: "Sorry, you are not allowed to create posts as this user.",…} code : "rest_cannot_create" data : {status: 401} message : "Sorry, you are not allowed to create posts as this user."

const AUTH_OBJ = 'OAuth oauth_consumer_key="hMZQANcBegerge",oauth_token="eger",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1496325588",oauth_nonce="oligrgGalWv",oauth_version="1.0",oauth_signature="v%2f4tiFyH1H46XKBXp6orthejy8Q44%253D"';

const URL = 'http://TEST.COM/wp-json/wp/v2/TEST';

 axios.post(URL,
 querystring.stringify({
        name: this.props.name
 }), {
  headers: { 
    'Content-Type': 'application/x-www-form-urlencoded',
    'Authorization': AUTH_OBJ
  }
 }).then((response) => {
    console.log('Response: ', response);
    if(response.status === 200) {
      console.log('RESPONSE 200');
    }
 });

I have it working using PostMan but cannot get this to work otherwise.

p.s All tokens etc in this post are just made up for example.

Phillip Hogan
  • 123
  • 1
  • 2
  • 9
  • I'm now getting the below error. Everything works using POSTMAN but when I try and generate the signature in my web App I get the error: {"code":"json_oauth1_signature_mismatch","message":"OAuth signature does not match","data":{"status":401}} – Phillip Hogan Jul 17 '17 at 10:02

0 Answers0