0

I can not get WP rest api working. No matter what I try I'm getting 401 (unauthorized). I've tried with Basic Auth and now I'm trying with OAuth1. I went through the process of getting the tokens and it works perfectly with Postman but when I try in WP with ajax I always get 401 error. My main question is is this set up right? Or how am I supposed to enter the credentials needed to authorize? If it's right then what else could be the problem for my 401 error? Thank you!

This is my current ajax code:

$.ajax({
            url: currentUser.siteURL + '/wp-json/wp/v2/posts/918',
            method: 'DELETE',
            typ: 'JSONP',
            crossDomain: true,
            beforeSend: function (xhr) {
                xhr.setRequestHeader('Authorization', 'OAuth oauth_consumer_key="xxxxxxx",oauth_token="xxxxxxxx",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1496702258",oauth_nonce="J8iG7e",oauth_version="1.0"');
            },
            success: function(data, txtStatus, xhr) {
                console.log(data);
                console.log(xhr.status);
            }
        });
mcirami
  • 3
  • 3

0 Answers0