Skip to content

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

Open
@velara3

Description

@velara3

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions