Basic Authentication not working for creating new post using WP REST API 2.0

I’m trying to create a new post using cUrl on my WordPress 4.3.1 site with below plugins:

I’ve added below code to my htaccess.conf file, because this thread told me so:

<IfModule !php5_module>
Define USE_PHP_FPM
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

Read More

Type in command line:

curl --data-binary "@updated-post.json" -H "Content-Type: application/javascript" --user "my_admin_user_name":"my_admin_password" http://www.mysite.nu/wp-json/wp/v2/posts

Contents of updated-post.json:

{
"title": "Hello Updated World!",
"content_raw": "<p>Howdy updated content.</p>",
"date": "2013-04-01T14:00:00+10:00"
}

Error code:

[{"code":"rest_forbidden","message":"You don't have permission to do this.","data":{"status":403}}]

The GET request does work. Some help would be much appreciated!

Related posts

1 comment

  1. I found that the problem is in the Basic Auth plugin. WP-API guys recommend using their own plugin and this solution works for me.

    1. Deactivate all activated basic auth plugins in your WordPress dashboard
    2. On the machine your WordPress is running go to the plugin folder
    3. Run

      git clone https://github.com/WP-API/Basic-Auth.git

    4. Go to your WordPress admin dashboard, plugins page. JSON Basic Authentication should be in the list. Activate it.

    Now creating a record via POST request should work.

Comments are closed.