Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rest_cannot_create Unauthorized error when creating post #44

Open
aymangithub opened this issue Aug 30, 2018 · 0 comments
Open

rest_cannot_create Unauthorized error when creating post #44

aymangithub opened this issue Aug 30, 2018 · 0 comments

Comments

@aymangithub
Copy link

Hi, please i have this error when trying to create post :
Response {_body: "{"code":"rest_cannot_create","message":"Sorry, you…reate posts as this user.","data":{"status":401}}", status: 401, ok: false, statusText: "Unauthorized", headers: Headers, …}
headers
:
Headers {_headers: Map(1), _normalizedNames: Map(1)}
ok
:
false
status
:
401
statusText
:
"Unauthorized"
type
:
2
url
:
"http://aqarat.estnhad.com/wp-json/wp/v2/posts"
_body
:
"{"code":"rest_cannot_create","message":"Sorry, you are not allowed to create posts as this user.","data":{"status":401}}"
proto
:
Body

and this the code:

console.log(this.values.userData.token);

let headers = new Headers();
headers.append('Content-Type', 'application/json;charset=UTF-8');
headers.append('Access-Control-Allow-Origin', '*');
headers.append('Access-Control-Allow-Headers', 'Content-Type, Content-Range, Content-Disposition, Content-Description');
headers.append('Access-Control-Allow-Methods', 'DELETE, HEAD, GET, OPTIONS, POST, PUT');
headers.append('Authorization', 'Bearer ' + this.values.userData.token);
headers.append('Cache-Control', 'no-cache');



this.wpApiPosts.create({ "title": 'wpapi angu title', "status": 'publish', "content": 'wpapi angu' }, headers)
  .toPromise()
  .then(response => response.json())
  .then(res => {
    console.log(res);
  })
  .catch(err => {
    console.log(err);
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant