question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sorry, you are not allowed to create posts as this user - Auth issue

See original GitHub issue

My “app”:

#!/bin/env node
var WPAPI = require('wpapi');
var myusername = 'xxx';
var mypassword = 'xxx';

//var wp = new WPAPI({ endpoint: 'http://site.org:8080/wp-json', username:myusername, password:mypassword });
//
var api = WPAPI.discover( 'http://site.org:8080' ).then(function( site ) {
    return site.auth({
        username: myusername,
        password: mypassword
    });
});
api.then(function (wp) {

wp.posts().create({
    title: 'Your Post Title',
    content: 'Your post content',
    status: 'publish'
}).then(function( response ) {
    console.log( response.id );
}).catch (function(e) {
        console.log(e);
});
});

Gives me:

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10

github_iconTop GitHub Comments

3reactions
AnnieAnithacommented, Aug 2, 2017

I was also having the same issue even after installing and activating the Basic Auth Plugin from https://wordpress.org/plugins/wp-basic-auth/#installation. It worked after installing it from https://github.com/WP-API/Basic-Auth

3reactions
kadamwhitecommented, May 17, 2017

There doesn’t appear to be anything wrong with your code; are you sure you have the Basic Authentication plugin installed & activated? Only cookie authentication is enabled by default, other authentication schemes require a specific plugin to be installed.

If you’ve already got that running and you still encounter this issue write back here and I’ll do what I can to help troubleshoot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a Post , via REST API: 401 Sorry, you are not allowed ...
I am working on creating an app, using this app I want to create a custom POST in user's WordPress account. I am...
Read more >
401 : Sorry, you are not allowed to create posts as this user #349
the account I am using is the Administrator and I have WP BASIC Auth (https://github.com/wokamoto/wp-basic-auth) plugin installed. { "data": { " ...
Read more >
Sorry, you are not allowed to create posts as this user using ...
i have added the following code to htaccess and add plugin (JSON Basic Authentication) then it start working.
Read more >
rest_cannot_create Sorry, you are not allowed to create posts ...
Following is the issue: { code: rest_cannot_create, message: Sorry, you are not allowed to create posts as this user., data: { status: 401...
Read more >
How to Fix "Sorry, You Are Not Allowed to Access This Page"
In this post, we'll dig into the “Sorry, you are not allowed to access this page” error and what causes it to occur....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found