[wp-trac] [WordPress Trac] #40697: Can't create new post by REST API but I can update existing post

WordPress Trac noreply at wordpress.org
Wed May 10 14:56:04 UTC 2017

#40697: Can't create new post by REST API but I can update existing post
 Reporter:  Alaa Rihan    |       Owner:
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:
Component:  REST API      |     Version:  4.7.4
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
Changes (by Alaa Rihan):

 * status:  closed => reopened
 * resolution:  invalid =>


 You are right about this but I fixed the url in my code, the problem still
 happening, this is my current code:

 jQuery( document ).ready( function ( $ ) {
     $( '.add-new-project button' ).click( function(e) {
         var title = 'test111';
         var excerpt = 'ssss';
         var content = 'cdffddfsf';
         var status = 'draft';

         var data = {
             title: title,
             excerpt: excerpt,
             content: content

             method: "POST",
             url: apiData.apiURL + 'posts',
             data: data,
             beforeSend: function ( xhr ) {
                 xhr.setRequestHeader( 'X-WP-Nonce', apiData.nonce );
             success : function( response ) {
                 console.log( response );
             fail : function( response ) {
                 console.log( response );



 } );

 my final url is like this:

 When I enter the url above in the browser I get posts in JSON format and
 when I send post request to edit existing post, the url will be like this:

 It works normally, the post updated correctly, but when I send post
 request to create new post to this url:

 I get 404 error!

Ticket URL: <https://core.trac.wordpress.org/ticket/40697#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list