Title: rest api custom endpoint
Last modified: September 15, 2019

---

# rest api custom endpoint

 *  Resolved [misaghlb](https://wordpress.org/support/users/misaghlb/)
 * (@misaghlb)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/rest-api-custom-endpoint/)
 * hi
    i have a custom endpoint for creating posts, the post will create successfully
   and published but won’t send to telegram. if i use the default endpoint -> POST/
   wp/v2/posts works fine and sends the post to Telegram. my Endpoint code is :
 *     ```
       function mycustom( WP_REST_Request $request ){
       	$my_post = array(
       		'post_title'    => $request['title'],
       		'post_content'  => $request['content'],
       		'post_status'   => $request['status'],
       		'post_excerpt'   => $request['excerpt'],
       		'post_author'   => 1,
       		'tax_input' => array( 'category' => $request['category'], 'post_tag' => $request['tags'])
       	);
   
       	// Insert the post into the database
       	$pid = wp_insert_post( $my_post );
   
       	return "ok";
       }
   
         add_action( 'rest_api_init', function () {
       	register_rest_route( 'wp/v2', '/mycustom', array(
       	  'methods' => 'POST',
       	  'callback' => 'cpost',
       	) );
         } );
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Manzoor Wani](https://wordpress.org/support/users/manzoorwanijk/)
 * (@manzoorwanijk)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/rest-api-custom-endpoint/#post-11933239)
 * Hello,
    Yes, the plugin expects every REST request to be from the default `posts`
   endpoint, so that it hooks into `rest_after_insert_{$post_type}` action.
 * I would suggest to do the same in your custom endpoint callback. Add this line
   after `wp_insert_post`:
 * `do_action( "rest_after_insert_{$my_post['post_type']}", get_post( $pid ), $request,
   true );`
 * Make sure to add `post_type` to post array.
 *  Thread Starter [misaghlb](https://wordpress.org/support/users/misaghlb/)
 * (@misaghlb)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/rest-api-custom-endpoint/#post-11933284)
 * it’s solved, thanks a lot for your awesome support and plugin.
 *  [Manzoor Wani](https://wordpress.org/support/users/manzoorwanijk/)
 * (@manzoorwanijk)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/rest-api-custom-endpoint/#post-11933293)
 * I’m glad it’s resolved 🙂
 * You are welcome. You may write a review for the plugin 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘rest api custom endpoint’ is closed to new replies.

 * ![](https://ps.w.org/wptelegram/assets/icon-256x256.png?rev=2500018)
 * [WP Telegram (Auto Post and Notifications)](https://wordpress.org/plugins/wptelegram/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wptelegram/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wptelegram/)
 * [Active Topics](https://wordpress.org/support/plugin/wptelegram/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wptelegram/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wptelegram/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Manzoor Wani](https://wordpress.org/support/users/manzoorwanijk/)
 * Last activity: [6 years, 8 months ago](https://wordpress.org/support/topic/rest-api-custom-endpoint/#post-11933293)
 * Status: resolved