Title: WP API can&#039;t create a post
Last modified: August 31, 2016

---

# WP API can't create a post

 *  [Goharika](https://wordpress.org/support/users/goharika/)
 * (@goharika)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/)
 * Hi WP API team,
    I need help connected with posting. I am trying to create new
   post, but getting error. Here is URL that I am sending POST request. I am using
   Basic authorization for authorization. [https://myblog.digitalpome.com/wp-json/wp/v2/posts](https://myblog.digitalpome.com/wp-json/wp/v2/posts)
 * Sending this data
    {“status”:”publish”,”title”:”PageTesto”,”content”:”Standart
   Content”}
 * Getting this error
    { “code”: “rest_cannot_create”, “message”: “Sorry, you are
   not allowed to create new posts.”, “data”: { “status”: 401 } }
 * [https://wordpress.org/plugins/rest-api/](https://wordpress.org/plugins/rest-api/)

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/wp-api-cant-create-a-post/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/wp-api-cant-create-a-post/page/2/?output_format=md)

 *  Thread Starter [Goharika](https://wordpress.org/support/users/goharika/)
 * (@goharika)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119540)
 * Hi does anybody have such problem too?
    I have find some of forums that they 
   are using oAuth for authentication, or some of them say to logout from wordpress
   dashboard then try to authorize with app, but that doesn’t help.
 *  Plugin Author [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * (@danielbachhuber)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119583)
 * If you’re seeing a 401 return status, it means your basic authorization isn’t
   working and the request is being treated as a logged-out request.
 *  Thread Starter [Goharika](https://wordpress.org/support/users/goharika/)
 * (@goharika)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119593)
 * May it come because of https? because before getting ssl that works
 *  Thread Starter [Goharika](https://wordpress.org/support/users/goharika/)
 * (@goharika)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119594)
 * I have changed Basic Auth now working with oAuth, and there is no authentication
   error.
 * I am getting this when trying to update existing post
    { “code”: “empty_content”,“
   message”: “Content, title, and excerpt are empty.”, “data”: { “status”: 400 }}
 * I am using postman tool for testing, I am choosing raw from Body tab and puting
   there my json
    { “title”: { “raw”: “Hello Digital World!!” }, “content”: { “raw”:“
   Hello Digital Updated World!!” }, “excerpt”: { “raw”: “test” } }
 *  [cb49747](https://wordpress.org/support/users/cb49747/)
 * (@cb49747)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119614)
 * I’m getting similar error. Any ideas?
 *  Plugin Author [Daniel Bachhuber](https://wordpress.org/support/users/danielbachhuber/)
 * (@danielbachhuber)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119615)
 * Are you setting the Content-Type header in the request?
 *  Thread Starter [Goharika](https://wordpress.org/support/users/goharika/)
 * (@goharika)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119622)
 * Yes we should content-type as json I have add and that’s worling
 *  [ardend](https://wordpress.org/support/users/ardend/)
 * (@ardend)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119628)
 * I am having the same issue you originally had Goharika. I am using angular in
   the front end and I want to use basic authorization. I have enqueued the api 
   and created the nonce:
 *     ```
       wp_localize_script( 'angular-core', 'RestAPI', array( 'url' => get_bloginfo('wpurl').'/wp-json/wp/v2/', 'nonce' => wp_create_nonce( 'wp_rest' ) ) );
       ```
   
 * I then have this form in html:
 *     ```
       <form ng-submit="processForm()">
   
       			<!-- Title -->
       			<div id="title_field" class="">
       			  <label>Title</label>
       			  <input type="text" name="title" class="" placeholder="Name of item" ng-model="formData.title">
   
       			</div>
   
       			<!-- Submit Button -->
       			<button type="submit" class="">
       			  <span class=""></span> Submit!
       			</button>
   
       		  </form>
       ```
   
 * And this is the processForm function in my controller:
 *     ```
       $scope.processForm = function() {
       			console.log(RestAPI.nonce);
   
       			$http({
       				method: 'POST',
       				url: '/wp-json/wp/v2/posts',
       				params: $scope.formData,
       				transformRequest: angular.identity,
       				headers: { 'Content-Type': 'multipart/form-data', 'X-WP-Nonce': RestAPI.nonce }
       			})
       			.success(function (result) {
       				console.log('Success!');
       			}).error(function () {
       				console.log('Fail!');
       			});
       		};
       ```
   
 * Adding the headers portion of the submit function got me from a 401 error to 
   a 403 error, saying the nonce is invalid. I don’t know what the deal is.
 * If it matters, while logged into the admin panel, if i go to the site and try
   and access users/me (which i know has issues listed in the documentation) I simply
   get logged out and repeatedly asked to login. Maybe i am misunderstanding the
   nonce usage?
 *  Thread Starter [Goharika](https://wordpress.org/support/users/goharika/)
 * (@goharika)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119634)
 * I can suggest to put in headers ‘Content-Type’: ‘application/json’.
    Also I have
   changed my authorization part, now I am using oAuth2, generating acces token 
   and putting that in URL
 *  [BenRacicot](https://wordpress.org/support/users/benracicot/)
 * (@benracicot)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119644)
 * Hey all, I have opened a question on the [WordPress.Stackexchange.com](http://wordpress.stackexchange.com/questions/220225/authenticating-a-user-with-the-wp-api-v2-in-postman)
   site regarding this exactly.
 * The documentation talks about the request header as ‘X-WP-Nonce’ and then sending
   along the nonce. Perhaps this is what most everyone’s issue is:
 *     ```
       beforeSend: function ( xhr ) {
               xhr.setRequestHeader( 'X-WP-Nonce', WP_API_Settings.nonce );
       }
       ```
   
 * However with Postman I cannot figure out how to do that?
 * Please take a look at the StackExchange question.
 *  [prasanth.p](https://wordpress.org/support/users/prasanthp/)
 * (@prasanthp)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119662)
 * Hey,
 * I got WP plugin for Basic Authentication through WP REST API. Please find the
   link [here](https://github.com/WP-API/Basic-Auth)
 *  [gurbrindersingh](https://wordpress.org/support/users/gurbrindersingh/)
 * (@gurbrindersingh)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119674)
 * I am using the rest api plugin (version 1) with basic auth plugin its not working
   error[
    { “code”: “json_cannot_edit”, “message”: “Sorry, you cannot edit this
   post” } ]
 * any idea ???
 *  [Matt](https://wordpress.org/support/users/matttaylor/)
 * (@matttaylor)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119676)
 * [@benracicot](https://wordpress.org/support/users/benracicot/) Thanks, that was
   my issue with Angular.
 * Postman shares cookies with Chrome. If you are logged into your site you may 
   see unexpected results.
 *  [mikelast](https://wordpress.org/support/users/mikelast/)
 * (@mikelast)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119682)
 * Hey Guys,
 * Been through the comments above and managed to fix my authentication issues –
   however I’m still getting a 400 error (see pasted code below). I am trying to
   send post 12 to [http://autoload.dev](http://autoload.dev) I have been through
   the DB and deleted every reference to post 12.
 *     ```
       Array
       (
           [headers] => Array
               (
                   [date] => Thu, 09 Jun 2016 11:43:49 GMT
                   [server] => Apache/2.2.29 (Unix) mod_wsgi/3.5 Python/2.7.10 PHP/5.6.10 mod_ssl/2.2.29 OpenSSL/0.9.8zh DAV/2 mod_fastcgi/2.4.6 mod_perl/2.0.9 Perl/v5.22.0
                   [access-control-allow-origin] => *
                   [access-control-allow-methods] => POST, GET, PUT, DELETE, OPTIONS
                   [access-control-allow-headers] => Array
                       (
                           [0] => X-Requested-With, content-type
                           [1] => Authorization
                       )
   
                   [x-powered-by] => PHP/5.6.10
                   [set-cookie] => PHPSESSID=3d20b969e225f5168b258a6fe94609ad; path=/
                   [expires] => Wed, 11 Jan 1984 05:00:00 GMT
                   [cache-control] => no-cache, must-revalidate, max-age=0
                   [pragma] => no-cache
                   [x-content-type-options] => nosniff
                   [access-control-expose-headers] => X-WP-Total, X-WP-TotalPages
                   [last-modified] =>
                   [allow] => GET, POST
                   [content-length] => 90
                   [connection] => close
                   [content-type] => application/json; charset=UTF-8
               )
   
           [body] => {"code":"rest_post_exists","message":"Cannot create existing post.","data":{"status":400}}
           [response] => Array
               (
                   [code] => 400
                   [message] => Bad Request
               )
   
           [cookies] => Array
               (
                   [0] => WP_Http_Cookie Object
                       (
                           [name] => PHPSESSID
                           [value] => 3d20b969e225f5168b258a6fe94609ad
                           [expires] =>
                           [path] => /
                           [domain] => autoload.dev
                       )
   
               )
   
           [filename] =>
       )
       ```
   
 * Can anyone explain what's going on
 *  [mikelast](https://wordpress.org/support/users/mikelast/)
 * (@mikelast)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/#post-7119683)
 * Been Googling since my earlier post and found this [Git Hub WP REST API post](https://github.com/WP-API/WP-API/issues/1716)
 * At the bottom of the post I saw this
 * > WordPress itself doesn’t really have APIs for inserting entries with new specific
   > IDs (except in doing imports, and that’s only a “suggestion” and shouldn’t 
   > be used here), so I’d think that the REST version certainly would not either.
 * Does that mean that I cannot create a post on another site with a specific ID?
   I am trying to `json_encode` a specific post from one site and post it through
   to another using `wp_remote_post`

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/wp-api-cant-create-a-post/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/wp-api-cant-create-a-post/page/2/?output_format=md)

The topic ‘WP API can't create a post’ is closed to new replies.

 * ![](https://ps.w.org/rest-api/assets/icon-256x256.png?rev=1346297)
 * [WordPress REST API (Version 2)](https://wordpress.org/plugins/rest-api/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/rest-api/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/rest-api/)
 * [Active Topics](https://wordpress.org/support/plugin/rest-api/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/rest-api/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/rest-api/reviews/)

## Tags

 * [create post](https://wordpress.org/support/topic-tag/create-post/)

 * 20 replies
 * 12 participants
 * Last reply from: [pcfjojo](https://wordpress.org/support/users/pcfjojo/)
 * Last activity: [9 years, 6 months ago](https://wordpress.org/support/topic/wp-api-cant-create-a-post/page/2/#post-8803736)
 * Status: not resolved