{"id":92871,"date":"2023-10-31T12:41:00","date_gmt":"2023-10-31T12:41:00","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=92871"},"modified":"2024-07-26T13:20:38","modified_gmt":"2024-07-26T13:20:38","slug":"add-custom-rest-api-route-wordpress","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/","title":{"rendered":"How to Add Custom REST API Route in WordPress?"},"content":{"rendered":"\n<p>WordPress provides us with the ability to create Custom <a href=\"https:\/\/webkul.com\/blog\/wordpress-rest-api\/\">WordPress REST API<\/a> Route and endpoints.<\/p>\n\n\n\n<p>You can use the Rewrites API, as well as the query classes:&nbsp;WP_Query,&nbsp;WP_User, etc) for creating your URL mappings, or custom queries.<\/p>\n\n\n\n<p>This blog describes &#8211; how we can add custom REST API routes in WordPress. The use of API is very common nowadays. <\/p>\n\n\n\n<p>So, when we work with API we need some custom routes along with default ones so that we can facilitate intended tasks.<\/p>\n\n\n\n<p>When we add our custom routes, we must not affect the default ones. We should add new routes with default ones, not in place of default routes. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Registering a Custom Rest Route<\/h2>\n\n\n\n<p>We can register a custom Rest API route through the function <code>register_rest_route<\/code>. <\/p>\n\n\n\n<p>The &nbsp;<code>register_rest_route<\/code> function takes three arguments: the namespace, the route we want, and the options. <\/p>\n\n\n\n<p>This function is added as a callback function to action rest_api_init. Let&nbsp;<code>webkul\/v1<\/code> be our namespace. <\/p>\n\n\n\n<p>We will explain this in detail in the namespaces later in the blog. Our registered route will match anything&nbsp;<code>\/webkulposts\/{id}<\/code>, where&nbsp;<code>{id}<\/code>&nbsp;is an integer.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example-<\/h3>\n\n\n\n<p>We use&nbsp;the rest_api_init hook which fires when preparing to serve an API request.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">add_action( 'rest_api_init', 'wk_register_custom_routes' );\n<\/pre>\n\n\n\n<p>Now, we register our route in the callback function of the above action using the function register_rest_route &#8211;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function wk_register_custom_routes() {\n\tregister_rest_route(\n\t\t'webkul\/v1',\n\t\t'\/webkulposts\/{id}',\n\t\tarray(\n\t\t\tarray(\n\t\t\t\t'methods'  =&gt; 'GET',\n\t\t\t\t'callback' =&gt; 'wk_get_post_callback',\n\t\t\t),\n\t\t\tarray(\n\t\t\t\t'methods'  =&gt; 'PUT',\n\t\t\t\t'callback' =&gt; 'wk_put_post_callback',\n\t\t\t),\n\t\t\tarray(\n\t\t\t\t'methods'  =&gt; 'DELETE,\n\t\t\t\t'callback' =&gt; 'wk_delete_post_callback',\n\t\t\t),\n\t\t)\n\t);\n}\n\npublic funcion wk_put_post_callback($request)\n{\n  \/\/ Your code \n}\n\npublic funcion wk_delete_post_callback($request )\n{\n  \/\/ Your code \n}<\/pre>\n\n\n\n<p>Here we have registered the three endpoints for the route. <\/p>\n\n\n\n<p>The  \u201croute\u201d refers to the URL, whereas the \u201cendpoint\u201d refers to the function behind it that corresponds to a method.<\/p>\n\n\n\n<p>Endpoints are nothing but the functions that can be accessed via the APIs. Endpoints take some number of parameters and return the requested data.<\/p>\n\n\n\n<p>The URL \u201cname\u201d you use to access endpoints, is called a route. A route can have multiple endpoints associated with it, which is used depending on the HTTP verb.<\/p>\n\n\n\n<p>For example, with the URL `http:\/\/webkul.com\/wp-json\/<code>webkul\/v1<\/code>\/<code>webkulposts<\/code>\/23`:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The \u201croute\u201d is&nbsp;<code><code>webkul\/v1<\/code>\/<code>webkulposts<\/code>\/23<\/code><\/li>\n\n\n\n<li>This route has 3 endpoints:\n<ul class=\"wp-block-list\">\n<li><code>GET<\/code>&nbsp;triggers a&nbsp;<code>wk_get_post_callback<\/code> &nbsp;method, returning the post data to the client.<\/li>\n\n\n\n<li><code>PUT<\/code>&nbsp;triggers an&nbsp;<code>wk_update_post_callback <\/code>method, taking the data to update, and returning the updated post data.<\/li>\n\n\n\n<li><code>DELETE<\/code>&nbsp;triggers a&nbsp;<code>wk_delete_post_callback<\/code>&nbsp;method, returning the now-deleted post data to the client.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>There may be any number of endpoints for each registered route, and for each endpoint, you can define the allowed HTTP methods. <\/p>\n\n\n\n<p>For each endpoint, you need to define a callback function for responding to the request and a permissions callback for creating custom permissions. <\/p>\n\n\n\n<p>You can also define allowed fields in the request and for each field specify a default value, a sanitization callback, a validation callback, and whether the field is required.<br><br>Explore our <a href=\"https:\/\/webkul.com\/woocommerce-api-development-services\/\">WooCommerce API Development Services<\/a> to see how we can help you to leverage the power of custom API routes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Components of Registered Route<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Namespaces<\/h3>\n\n\n\n<p>Namespaces serve as the initial component of the endpoint URL and are crucial for preventing conflicts between custom routes. <\/p>\n\n\n\n<p>By employing namespaces, conflicts can be avoided when two plugins attempt to add a route with the same name but offer distinct functionalities.<\/p>\n\n\n\n<p>In general, for namespaces, you should adopt the pattern of plugin_name\/v1.<\/p>\n\n\n\n<p>Here the plugin_name typically corresponds to your <a href=\"https:\/\/store.webkul.com\/woocommerce-plugins.html\" target=\"_blank\" rel=\"noreferrer noopener\">WooCommerce plugin<\/a> or theme slug, while v1 denotes the initial version of the API. <\/p>\n\n\n\n<p>In the route registered in the previous section &#8211; <code>webkul\/v1<\/code> is our namespace.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Arguments<\/h3>\n\n\n\n<p>In the key <code>args<\/code> for each endpoint in WordPress, the arguments are defined as a map. <\/p>\n\n\n\n<p>The map uses the argument name as the key, with the value being a map of options for that argument.<\/p>\n\n\n\n<p> This options map can include keys such as <code>default<\/code>, <code>required<\/code>, <code>sanitize_callback<\/code>, and <code>validate_callback<\/code>.<\/p>\n\n\n\n<p>The <code>default<\/code> key is used to set a default value for the argument if none is supplied.<\/p>\n\n\n\n<p> If the argument is not provided and no default value is set, the argument will be empty.<\/p>\n\n\n\n<p>The <code>required<\/code> key, when set to <code>true<\/code>, ensures that the argument is mandatory. If no value is passed for a required argument, an error will be returned. <\/p>\n\n\n\n<p>However, if a default value is set, the argument will always have a value and the <code>required<\/code> setting will have no effect.<\/p>\n\n\n\n<p>The <code>validate_callback<\/code> key allows you to specify a function that will receive the value of the argument. <\/p>\n\n\n\n<p>This function should return <code>true<\/code> if the value is considered valid and <code>false<\/code> otherwise. It provides a way to validate the input data before further processing.<\/p>\n\n\n\n<p>The <code>sanitize_callback<\/code> key allows you to specify a function that will sanitize the value of the argument before passing it to the main callback. <\/p>\n\n\n\n<p>Sanitization helps to ensure that the input is safe and conforms to the expected format or type.<\/p>\n\n\n\n<p>By utilising the <code>sanitize_callback<\/code> and <code>validate_callback<\/code> options, <\/p>\n\n\n\n<p>the main callback function can focus solely on processing the request and preparing the data to be returned, using the <code>WP_REST_Response<\/code> class. <\/p>\n\n\n\n<p>These callbacks provide a reliable way to validate and sanitize the input, allowing you to work with trustworthy and secure data during the processing phase.<\/p>\n\n\n\n<p>Let&#8217;s add an argument to our previously registered route which checks if the value supplied for id is numeric or not.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">function wk_register_custom_routes() {\n\tregister_rest_route(\n\t\t&#039;webkul\/v1&#039;,\n\t\t&#039;\/webkulposts\/{id}&#039;,\n\t\tarray(\n\t\t\tarray(\n\t\t\t\t&#039;methods&#039;  =&gt; &#039;GET&#039;,\n\t\t\t\t&#039;callback&#039; =&gt; &#039;wk_get_post_callback&#039;,\n\t\t\t\t&#039;args&#039;     =&gt; array(\n\t\t\t\t\t&#039;id&#039; =&gt; array(\n\t\t\t\t\t\t&#039;validate_callback&#039; =&gt;     function( $param, $request, $key ) {\n\t\t\t\t\t\t\treturn is_numeric( $param );\n\t\t\t\t\t\t},\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t),\n\t\t\tarray(\n\t\t\t\t&#039;methods&#039;  =&gt; &#039;PUT&#039;,\n\t\t\t\t&#039;callback&#039; =&gt; &#039;wk_put_post_callback&#039;,\n\t\t\t),\n\t\t\tarray(\n\t\t\t\t&#039;methods&#039;  =&gt; &#039;DELETE&#039;,\n\t\t\t\t&#039;callback&#039; =&gt; &#039;wk_delete_post_callback&#039;,\n\t\t\t),\n\t\t)\n\t);\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Permission Callback<\/h3>\n\n\n\n<p>When working with endpoints in WordPress, it is important to register a permissions callback. <\/p>\n\n\n\n<p>This function will check if the user has the necessary permissions to perform the desired action (such as reading or updating) before the actual callback is executed. <\/p>\n\n\n\n<p>To register the permissions callback, you can use the <code>permission_callback<\/code> option alongside the callback option within the endpoint configuration. <\/p>\n\n\n\n<p>This callback should return either a boolean value or an instance of <code>WP_Error<\/code>. If the function returns true, the response will be processed.<\/p>\n\n\n\n<p> A default error message will be returned if it returns false, and the request will not proceed with further processing.<\/p>\n\n\n\n<p> In the case of an <code>WP_Error<\/code> instance, that specific error will be returned to the client.<\/p>\n\n\n\n<p>It&#8217;s important to note that the permissions callback is executed after remote authentication, which sets the current user. <\/p>\n\n\n\n<p>This means you can utilize <code>current_user_can<\/code>  the function to check if the authenticated user possesses the necessary capability for the action.<\/p>\n\n\n\n<p>Once you have registered a <code>permission_callback<\/code> , it becomes necessary to authenticate your requests.<\/p>\n\n\n\n<p>It can by done by including a nonce parameter or using other authentication methods. <\/p>\n\n\n\n<p>Failure to authenticate your requests will result in a rest_forbidden error. For more detailed authentication information, refer to the relevant documentation. <\/p>\n\n\n\n<p>Let&#8217;s add a permission callback to our previously registered route.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\"> register_rest_route( &#039;&lt;span style=&quot;background-color: initial;font-family: inherit;font-size: inherit;color: initial&quot;&gt;webkul\/v1&#039;, &#039;&lt;\/span&gt;&lt;span style=&quot;font-family: inherit;font-size: inherit;color: initial&quot;&gt;\/webkulposts\/{id}&lt;\/span&gt;&#039;, array(\n       &#039;methods&#039;  =&gt; &#039;GET&#039;,\n       &#039;callback&#039; =&gt; &#039;wk_get_post_callback&#039;,\n        &#039;args&#039; =&gt; array(\n        &#039;id&#039; =&gt; array(\n        &#039;validate_callback&#039; =&gt; function($param, $request, $key) {\n                return is_numeric( $param );\n                }\n          ),\n         &#039;permission_callback&#039; =&gt; function () {\n                return current_user_can( &#039;edit_others_posts&#039; );\n         }\n       ),\n    }\n   )  );<\/pre>\n\n\n\n<p>In case you intend to keep your REST API endpoint public, you can use &nbsp;__return_true&nbsp;as the permission callback.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Return Value<\/h3>\n\n\n\n<p>Once the callback function executes, and then it sends the resulting value back to the client after undergoing JSON conversion. <\/p>\n\n\n\n<p>This enables the ability to return a wide range of data types. <\/p>\n\n\n\n<p>In the aforementioned example, we return either a string or null, and the API automatically handles the conversion to JSON.<\/p>\n\n\n\n<p>Similar to any other WordPress function, it is also possible to return a WP_Error instance. <\/p>\n\n\n\n<p>For more info &#8211; <a href=\"https:\/\/developer.wordpress.org\/rest-api\/extending-the-rest-api\/adding-custom-endpoints\/\" rel=\"nofollow\">Adding Custom Endpoints<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Support<\/h2>\n\n\n\n<p>For any technical assistance kindly&nbsp;<a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\" target=\"_blank\" rel=\"noreferrer noopener\">raise&nbsp;a ticket<\/a>&nbsp;or&nbsp;reach&nbsp;us by email at&nbsp;support@webkul.com. Thanks for Your Time! Have a Good Day!<\/p>\n\n\n\n<p>Also, discover various solutions to add more features and enhance your online store by visiting the&nbsp;<a href=\"https:\/\/store.webkul.com\/woocommerce-plugins.html\" target=\"_blank\" rel=\"noreferrer noopener\">WooCommerce plugins<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress provides us with the ability to create Custom WordPress REST API Route and endpoints. You can use the Rewrites API, as well as the query classes:&nbsp;WP_Query,&nbsp;WP_User, etc) for creating your URL mappings, or custom queries. This blog describes &#8211; how we can add custom REST API routes in WordPress. The use of API is <a href=\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":339,"featured_media":62819,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1773,1260],"tags":[2253,1468,1258],"class_list":["post-92871","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-woocommerce","category-wordpress","tag-rest-api","tag-woocommerce","tag-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Custom REST API Route Wordpress<\/title>\n<meta name=\"description\" content=\"Add Custom REST API Route WordPress, sometime there is a need for custom endpoints where custom actions can be performed.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Custom REST API Route Wordpress\" \/>\n<meta property=\"og:description\" content=\"Add Custom REST API Route WordPress, sometime there is a need for custom endpoints where custom actions can be performed.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-31T12:41:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-26T13:20:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Gaurav Sharma\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Gaurav Sharma\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/\"},\"author\":{\"name\":\"Gaurav Sharma\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/40772eda35ff65fccf74b6dd98cb9a31\"},\"headline\":\"How to Add Custom REST API Route in WordPress?\",\"datePublished\":\"2023-10-31T12:41:00+00:00\",\"dateModified\":\"2024-07-26T13:20:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/\"},\"wordCount\":1207,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet-1.png\",\"keywords\":[\"REST API\",\"WooCommerce\",\"wordpress\"],\"articleSection\":[\"WooCommerce\",\"WordPress\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/\",\"url\":\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/\",\"name\":\"Custom REST API Route Wordpress\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet-1.png\",\"datePublished\":\"2023-10-31T12:41:00+00:00\",\"dateModified\":\"2024-07-26T13:20:38+00:00\",\"description\":\"Add Custom REST API Route WordPress, sometime there is a need for custom endpoints where custom actions can be performed.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet-1.png\",\"width\":825,\"height\":260,\"caption\":\"Creating New shipping method in woocommerce\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Add Custom REST API Route in WordPress?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/40772eda35ff65fccf74b6dd98cb9a31\",\"name\":\"Gaurav Sharma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fceee8dd8a1d417863937db5bc8989d9ee806b37c5c28734ad8c6d198ae5587a?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fceee8dd8a1d417863937db5bc8989d9ee806b37c5c28734ad8c6d198ae5587a?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Gaurav Sharma\"},\"description\":\"A skilled professional in the WordPress department, specializes in SOAP, GraphQL and WordPress SaaS Development. With expertise in WooCommerce Migration Services and proficiency in Facebook &amp; WhatsApp API Integrations, as well as Connectors to eBay, Gaurav delivers innovative and scalable solutions.\",\"url\":\"https:\/\/webkul.com\/blog\/author\/gaurav-sharma747\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Custom REST API Route Wordpress","description":"Add Custom REST API Route WordPress, sometime there is a need for custom endpoints where custom actions can be performed.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/","og_locale":"en_US","og_type":"article","og_title":"Custom REST API Route Wordpress","og_description":"Add Custom REST API Route WordPress, sometime there is a need for custom endpoints where custom actions can be performed.","og_url":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2023-10-31T12:41:00+00:00","article_modified_time":"2024-07-26T13:20:38+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet-1.png","type":"image\/png"}],"author":"Gaurav Sharma","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Gaurav Sharma","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/"},"author":{"name":"Gaurav Sharma","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/40772eda35ff65fccf74b6dd98cb9a31"},"headline":"How to Add Custom REST API Route in WordPress?","datePublished":"2023-10-31T12:41:00+00:00","dateModified":"2024-07-26T13:20:38+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/"},"wordCount":1207,"commentCount":1,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet-1.png","keywords":["REST API","WooCommerce","wordpress"],"articleSection":["WooCommerce","WordPress"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/","url":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/","name":"Custom REST API Route Wordpress","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet-1.png","datePublished":"2023-10-31T12:41:00+00:00","dateModified":"2024-07-26T13:20:38+00:00","description":"Add Custom REST API Route WordPress, sometime there is a need for custom endpoints where custom actions can be performed.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/10\/WordPress-Code-Snippet-1.png","width":825,"height":260,"caption":"Creating New shipping method in woocommerce"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/add-custom-rest-api-route-wordpress\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Add Custom REST API Route in WordPress?"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/40772eda35ff65fccf74b6dd98cb9a31","name":"Gaurav Sharma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/fceee8dd8a1d417863937db5bc8989d9ee806b37c5c28734ad8c6d198ae5587a?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fceee8dd8a1d417863937db5bc8989d9ee806b37c5c28734ad8c6d198ae5587a?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Gaurav Sharma"},"description":"A skilled professional in the WordPress department, specializes in SOAP, GraphQL and WordPress SaaS Development. With expertise in WooCommerce Migration Services and proficiency in Facebook &amp; WhatsApp API Integrations, as well as Connectors to eBay, Gaurav delivers innovative and scalable solutions.","url":"https:\/\/webkul.com\/blog\/author\/gaurav-sharma747\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/92871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/339"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=92871"}],"version-history":[{"count":84,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/92871\/revisions"}],"predecessor-version":[{"id":455062,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/92871\/revisions\/455062"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/62819"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=92871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=92871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=92871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}