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

Checking if login works after "Sorry, you are not allowed to edit this post."? #66

Open
velara3 opened this issue Jun 12, 2020 · 0 comments

Comments

@velara3
Copy link

velara3 commented Jun 12, 2020

I'm getting an error message when I'm attempting to update a post.

How do I know if login is successful?

I'm able to get a list of posts so the endpoint works.

I'm using the following:

	  var wp = new WPAPI({
			endpoint: apiRoot,
			username: username,
			password: credential,
			auth: true
	  });

	  var test = "posts";

	  // get posts
	  if (test=="posts") {
		log('verify endpoint')
		  wp.posts().then(function( response ) {
				log("response", response)
			}).catch(function(error) {
				log("error", error)
			})
			return;
	  }
	  
	if (test=="update") {
		var postNumber = 28;
		
		var date = new Date()
		var time = date.getTime();
		var update = wp.posts().auth().id( postNumber ).update({
			title: "Time " + time
		})
		.then(function(response){
			console.log("complete");
			console.log(response);
		})
		.catch(function(err){
			log("error:", err);
		});
	}

I've installed and activated this plugin.

{ code: 'rest_cannot_edit',
  message: 'Sorry, you are not allowed to edit this post.',
  data: { status: 401 } 
}

Attempting to create a post returns this:

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

I'm using the download of wpapi.js (7/6/2017) here:

http://wp-api.org/node-wpapi/installation/

FYI I'm not on node. I'm in a client that runs ES6.

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