So, I spent days getting the oAuth authentication token and I am finally able to create posts using Postman.

Now I’m trying to implement the authentication on my site and am getting a 401 error. My request header looks like this:

createRecipe.open("POST", "/wp-json/wp/v2/recipes");
  createRecipe.setRequestHeader("Authorization",
                                'OAuth oauth_consumer_key="2ZbpQzTR3B5b",oauth_token="Luz5LnEzpt5axVBf4GDT5fE8",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1491374534",oauth_nonce="qHW1BG",oauth_version="1.0",oauth_signature="VNv4lP6ogZ3778wLrdQpGzloE9U%3D"');
                            createRecipe.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  createRecipe.send(JSON.stringify(recipeData));
  createRecipe.onreadystatechange = function() {
    if (createRecipe.readyState == 4) {
      if (createRecipe.status == 201) {
        console.log('Created Recipe!');
        console.log(recipeData);

      } else {
        alert("Error - try again.");
      }
    }
  }

Here it is, working in Postman:

What am I missing here??

Read more here: Posting to WordPress API using oAuth1.0 authentication


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: