unabe to post using wordpress api

Please do not mark it as duplicate. Solution on those post doesn’t seem to work.

I want to post on my wordpress blog remotely using curl.

I am using this curl command to post to wordpress

curl -D- -X POST -H "Authorization: Basic bTRtdxXM6R3JTcnYyMDA299999" -H "Content-Type: application/json" --data '{"title": "this is my new post sent from curl","content": "This is the content","status": "publish"}' "http://mywebsite.com/wp-json/wp/v2/posts

The response I am getting is

    HTTP/1.1 401 Unauthorized
Date: Thu, 13 Apr 2017 19:47:42 GMT
Content-Type: application/json; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=d2221a0a91149358bf8744eb3d5816cea1492112861; expires=Fri, 13-Apr-18 19:47:41 GMT; path=/; domain=.mywebsite.com; HttpOnly
X-Powered-By: PHP/5.6.30
X-Robots-Tag: noindex
Link: <http://mywebsite.com/wp-json/>; rel="https://api.w.org/"
X-Content-Type-Options: nosniff
Access-Control-Expose-Headers: X-WP-Total, X-WP-TotalPages
Access-Control-Allow-Headers: Authorization, Content-Type
Allow: GET
Vary: Accept-Encoding,User-Agent
Server: cloudflare-nginx
CF-RAY: 34f0f046a79f081d-SIN

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

I have tried everything that I could but couldn’t get it to work. Someone suggested adding the following to htaccess which didn’t work

<IfModule mod_rewrite.c>
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

I tried installing https://wordpress.org/plugins/rest-api/ plugin as well.

Current PHP version: 5.6
hosted on Godaddy economy hosting.
Wordpress version:WordPress 4.7.3

Please help, I have been trying for few days now and none of the solutions seem to work.

Read more here: unabe to post using wordpress api

Leave a Reply

Your email address will not be published. Required fields are marked *