unabe to post using wordpress api
-
Please help, I have tried everything I can. I need a working example to create a new post.
I even asked on Stakoverflow, but no one helped. I feel I am doing something very stupid.
I have even tried wp_remote_post like in this solution:
http://stackoverflow.com/questions/37243266/wordpress-rest-api-how-to-postI want to post on my wordpress blog remotely using curl. (or PHP, Python, Perl)
I am using this curl command to post to wordpress
curl -D- -X POST -H "Authorization: Basic [auth key redacted]" -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/postsThe 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
# BEGIN WP BASIC Auth <IfModule mod_rewrite.c> RewriteCond %{HTTP:Authorization} ^(.*) RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1] </IfModule> # END WP BASIC AuthI 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.
The topic ‘unabe to post using wordpress api’ is closed to new replies.