Title: Custom Endpoint Help
Last modified: August 2, 2019

---

# Custom Endpoint Help

 *  Resolved [sharulhafiz](https://wordpress.org/support/users/sharulhafiz/)
 * (@sharulhafiz)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/custom-endpoint-help/)
 * I tried to register custom endpoint, but it doesn’t seem to work, nothing appears
   Endpoint API Caches. Here is my code:
 *     ```
       add_action( 'rest_api_init', function () {
         register_rest_route( 'utmsmart', '/(?P<slug>[a-zA-Z0-9-]+)', array(
           'methods' => 'GET',
           'callback' => 'beforeyouarrive_query',
         ) );
       } );
   
       /**
        * Register the /wp-json/utmsmart/(?P<slug>[a-zA-Z0-9-]+) endpoint so it will be cached.
        * 
        */
       function wprc_add_acf_posts_endpoint( $allowed_endpoints ) {
           if ( ! isset( $allowed_endpoints[ 'utmsmart' ] ) || ! in_array( '/(?P<slug>[a-zA-Z0-9-]+)', $allowed_endpoints[ 'utmsmart' ] ) ) {
               $allowed_endpoints[ 'utmsmart' ][] = '/(?P<slug>[a-zA-Z0-9-]+)';
           }
           return $allowed_endpoints;
       }
       add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_acf_posts_endpoint', 10, 1);
       ```
   

Viewing 1 replies (of 1 total)

 *  Plugin Author [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * (@rockfire)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/custom-endpoint-help/#post-11800881)
 * Hi [@sharulhafiz](https://wordpress.org/support/users/sharulhafiz/)
 * Thank you for using our plugin!
 * The reason this isn’t working is because you are registering your rest route 
   incorrectly. The first argument of `register_rest_route` should be a namespace(
   like `'wp/v2'`) and the second argument should be the route (like `'/posts/(?
   P<id>\d+)'`). So in your case it should be something like this:
    `register_rest_route('
   sharulhafiz/v1', '/utmsmart/(?P<slug>[a-zA-Z0-9-]+)', ... )` See: [https://developer.wordpress.org/reference/functions/register_rest_route/](https://developer.wordpress.org/reference/functions/register_rest_route/)
   and [https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/](https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/)
 * If you register your rest route like that you can register it for caching like
   this:
    `$allowed_endpoints[ 'sharulhafiz/v1' ][] = 'utmsmart';`

Viewing 1 replies (of 1 total)

The topic ‘Custom Endpoint Help’ is closed to new replies.

 * ![](https://ps.w.org/wp-rest-cache/assets/icon-256x256.png?rev=3328849)
 * [WP REST Cache](https://wordpress.org/plugins/wp-rest-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-rest-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-rest-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-rest-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-rest-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-rest-cache/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Richard Korthuis](https://wordpress.org/support/users/rockfire/)
 * Last activity: [6 years, 10 months ago](https://wordpress.org/support/topic/custom-endpoint-help/#post-11800881)
 * Status: resolved