7

I want to post articles with rest on one of my wordpress.com websites (wordpress website hosted on the free wordpress.com platform).

Endpoint, GET on: https://public-api.wordpress.com/wp/v2/sites/donnadulcinea.wordpress.com/posts

With Basic-Auth header. Body of the request (for test),

{"title":"New Rest Post"}

Response:

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

What's wrong? Where may I found one final example for a really simple posting on a wordpress.com domain?

1
  • 1
    Try the Application passwords plugin Commented Oct 12, 2019 at 18:36

3 Answers 3

7

First, are you using the basic auth plugin? here

Second, I'm not sure if your endpoint is correct. This is how I use:

http://localhost/wp-json/wp/v2/posts

I tried in my website, with this json:

{
    "title":"title",
    "content":"content",
    "categories":"news",
    "status":"publish"
}

and it worked

Sign up to request clarification or add additional context in comments.

1 Comment

i was fool trying so many plugins but "JSON Basic Authentication" was the plugin who did the job simple solution great answer.
1

I just faced the same issue. Download the miniOrange API Authentication plugin. Then, if running on an Apache server, add the below two lines to your .htaccess file after the RewriteBase:

RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] 

Works like a charm.

Comments

-1

I encountered an error while trying to access the API locally:

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

I found a solution. Add this to your wp-config file:

define( 'WP_ENVIRONMENT_TYPE', 'local' );

1 Comment

Don't do that - there are good security reasons not to change the environment type to local.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.