Title: unabe to post using wordpress api
Last modified: April 16, 2017

---

# unabe to post using wordpress api

 *  [kontactg](https://wordpress.org/support/users/kontactg/)
 * (@kontactg)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/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-post](http://stackoverflow.com/questions/37243266/wordpress-rest-api-how-to-post)
 * I 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/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
 *     ```
       # BEGIN WP BASIC Auth
       <IfModule mod_rewrite.c>
       RewriteCond %{HTTP:Authorization} ^(.*)
       RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
       </IfModule>
       # END WP BASIC Auth
       ```
   
 * I tried installing [https://wordpress.org/plugins/rest-api/](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.
    -  This topic was modified 9 years, 2 months ago by [bcworkz](https://wordpress.org/support/users/bcworkz/).
      Reason: Auth key redacted

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/unabe-to-post-using-wordpress-api/#post-9035796)
 * I did’t know if the auth key in your cURL example was real or not, so I removed
   it. If it was real, even though it didn’t work in this case, it could still allow
   unwanted access in other ways. To be safe you should remove this key. I realize
   you haven’t provided a valid domain, but just in case it should come up later,
   someone could put the two together to gain access.
 * What is the nature of the app you are using for requests? If it’s a theme or 
   plugin on the same site, the user must be logged in and have publish_posts capability.
   Cookies are then used for authentication. You just need to send a proper nonce
   with your request.
 * Otherwise you need an authentication plugin of some sort. Cookie authentication
   is the only authentication mechanism available natively within WordPress. Plugins
   may be added to support alternative modes of authentication that will work from
   remote applications. Some example plugins are [OAuth 1.0a Server](https://wordpress.org/plugins/rest-api-oauth1/),
   [Application Passwords](https://wordpress.org/plugins/application-passwords/),
   and [JSON Web Tokens](https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/).

Viewing 1 replies (of 1 total)

The topic ‘unabe to post using wordpress api’ is closed to new replies.

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [rest](https://wordpress.org/support/topic-tag/rest/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [9 years, 2 months ago](https://wordpress.org/support/topic/unabe-to-post-using-wordpress-api/#post-9035796)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
