{"id":11978,"date":"2016-11-24T16:50:19","date_gmt":"2016-11-24T13:50:19","guid":{"rendered":"http:\/\/blog.belvg.com\/?p=11978"},"modified":"2021-02-18T14:00:28","modified_gmt":"2021-02-18T12:00:28","slug":"how-to-create-custom-api-in-magento-2","status":"publish","type":"post","link":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html","title":{"rendered":"How to Create Custom API in Magento 2"},"content":{"rendered":"\n<p>Today I&rsquo;d like to guide you through the process of creating Custom API in Magento 2.<\/p>\n<p>At first, we must create the primary files of a module.<\/p>\n<p><!--more--><\/p>\n<p>composer.json:<\/p>\n<pre class=\"lang:php decode:true \">{\r\n \"name\": \"belvg\/customapi\",\r\n \"description\": \"CustomAPI\",\r\n \"repositories\": [\r\n   {\r\n     \"type\": \"composer\",\r\n     \"url\": \"https:\/\/repo.magento.com\/\"\r\n   }\r\n ],\r\n \"require\": {\r\n   \"php\": \"~5.5.0|~5.6.0|~7.0.0\",\r\n },\r\n \"type\": \"magento2-module\",\r\n \"version\": \"1.0.0\",\r\n \"autoload\": {\r\n   \"files\": [ \"registration.php\" ],\r\n   \"psr-4\": {\r\n     \"Belvg\\\\CustomAPI\\\\\": \"\"\r\n   }\r\n }\r\n}\r\n<\/pre>\n<p>registration.php:<\/p>\n<pre class=\"lang:php decode:true \">&lt;?php\r\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\r\n   \\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\r\n   'Belvg_CustomAPI',\r\n   __DIR__\r\n);\r\n<\/pre>\n<div class=\"module_in_content_container\"><a href=\"https:\/\/store.belvg.com\/\" class=\"link_to_module\" target=\"_blank\" rel=\"noopener\"><\/a><div class=\"module_content\"><img src=\"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2016\/04\/Extensions_for_Magento_2.png\" width=\"120\" height=\"120\" alt=\"Extensions for Magento 2\" class=\"module_image\" title=\"How to Create Custom API in Magento 2\"><div class=\"module_content_part\"><h3 class=\"title\">Magento 2 Extensions<\/h3><p class=\"module_content_text\">Take your online store to the next level with BelVG Magento 2 Extensions<\/p><a href=\"https:\/\/store.belvg.com\/\" class=\"link_2_to_module\" target=\"_blank\" style=\"display:inline-block\" rel=\"noopener\"><span class=\"read-more\">Visit the store<\/span><\/a><\/div><\/div><\/div>\n<p>etc\/module.xml:<\/p>\n<pre class=\"lang:php decode:true \">&lt;?xml version=\"1.0\"?&gt;\r\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"       xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Module\/etc\/module.xsd\"&gt;\r\n   &lt;module name=\"Belvg_CustomAPI\"\r\n           setup_version=\"1.0.0\" \/&gt;\r\n&lt;\/config&gt;\r\n<\/pre>\n<p>The second step is &ndash; create an interface for custom API. Let&rsquo;s create<em> Api\/TestInterface.php <\/em>file and save it with the following content:<\/p>\n<pre class=\"lang:php decode:true\">&lt;?php\r\nnamespace Belvg\\CustomAPI\\Api;\r\n\r\ninterface TestInterface\r\n{\r\n   \/**\r\n    * Test function\r\n    *\r\n    * @api\r\n    * @return string\r\n    *\/\r\n   public function test();\r\n\r\n   \/**\r\n    * Test function\r\n    *\r\n    * @api\r\n    * @param string $param\r\n    * @return string\r\n    *\/\r\n   public function test1($param);\r\n}\r\n<\/pre>\n<p>That&rsquo;s how we created an interface with the following functions:<\/p>\n<p><em>test() <\/em>function, it doesn&rsquo;t receive any parameters;<\/p>\n<p><em>test1($param), <\/em>it does receive 1 parameter in order of the call to our API.<\/p>\n<p>Now we must create a model, that would work through our interface. Let&rsquo;s create <em>Model\/Test.php <\/em>file and write the following code into it:<\/p>\n<pre class=\"lang:php decode:true\">&lt;?php\r\nnamespace Belvg\\CustomAPI\\Model;\r\nclass Test implements \\Belvg\\CustomAPI\\Api\\TestInterface\r\n{\r\n   \/**\r\n    * Test function\r\n    *\r\n    * @api\r\n    * @return string\r\n    *\/\r\n   public function test() {\r\n       return 'test';\r\n   }\r\n   \/**\r\n    * Test function\r\n    *\r\n    * @api\r\n    * @param string $param\r\n    * @return string\r\n    *\/\r\n   public function test1($param){\r\n       return $param;\r\n   }\r\n}\r\n<\/pre>\n<p>We have just created a model, which is inherited by our interface and we described functions that are called in it. After that, we must connect our interface with the model. Please do the following to perform it:<\/p>\n<p>Create <em>etc\/di.xml <\/em>file with the following content:<\/p>\n<pre class=\"lang:php decode:true \">&lt;?xml version=\"1.0\"?&gt;\r\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\nxsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager\/etc\/config.xsd\"&gt;\r\n   &lt;preference for=\"Belvg\\CustomAPI\\Api\\TestInterface\"\r\n               type=\"Belvg\\CustomAPI\\Model\\Test\" \/&gt;\r\n&lt;\/config&gt;\r\n<\/pre>\n<p>Then we create a path to call our API. For that we write the following in <em>etc\/webapi.xml <\/em>file:<\/p>\n<pre class=\"lang:php decode:true\">&lt;?xml version=\"1.0\"?&gt;\r\n&lt;routes xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"..\/..\/..\/..\/..\/app\/code\/Magento\/Webapi\/etc\/webapi.xsd\"&gt;\r\n   &lt;route url=\"\/V1\/test\/\" method=\"GET\"&gt;\r\n       &lt;service class=\"Belvg\\CustomAPI\\Api\\TestInterface\"\r\n                method=\"test\"\/&gt;\r\n       &lt;resources&gt;\r\n           &lt;resource ref=\"anonymous\"\/&gt;\r\n       &lt;\/resources&gt;\r\n   &lt;\/route&gt;\r\n   &lt;route url=\"\/V1\/test1\/:param\" method=\"GET\"&gt;\r\n       &lt;service class=\"Belvg\\CustomAPI\\Api\\TestInterface\"\r\n                method=\"test1\"\/&gt;\r\n       &lt;resources&gt;\r\n           &lt;resource ref=\"anonymous\"\/&gt;\r\n       &lt;\/resources&gt;\r\n   &lt;\/route&gt;\r\n&lt;\/routes&gt;\r\n<\/pre>\n<p>Here we specified 2 paths to our functions:<\/p>\n<p>\/V1\/test\/ , which calls <em>test<\/em> method in<em> TestInterface<br>\n<\/em>\/V1\/test1\/:param, which calls <em>test1<\/em> method in <em>TestInterface, <\/em>receives parameter and transfers it into the function.<\/p>\n<p>API is called through the GET method, but you can change it to POST, DELETE or some other methods if you want.<\/p>\n<div class=\"content_sales_info\" style=\"background-image: url(https:\/\/belvg.com\/blog\/wp-content\/uploads\/2019\/03\/Sales_background.png\"><img width=\"65\" height=\"65\" src=\"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2015\/11\/Andrey_Dubina.png\" alt=\"Andrey_Dubina\" title=\"How to Create Custom API in Magento 2\"><div class=\"content_part\"><h3 class=\"title\">Partner With Us <\/h3><span class=\"sales_content_text\">Let's discuss how to grow your business. Get a Free Quote.<\/span><\/div> <a class=\"call-to-action\" href=\"https:\/\/belvg.com\/contact?utm_source=blog&amp;utm_campaign=sales_block&amp;utm_content=middle\" target=\"_blank\" rel=\"noopener\">Talk to Andrey<\/a><\/div>\n<p>Also you are able to specify users group, that have permission to call your API or you can specify your own rule through the following structure, which is described in<em> &lt;route&gt;&lt;\/route&gt;:<\/em><\/p>\n<pre class=\"lang:php decode:true \">       &lt;resources&gt;\r\n           &lt;resource ref=\"anonymous\"\/&gt;\r\n       &lt;\/resources&gt;\r\n<\/pre>\n<p>And it&rsquo;s possible to indicate <em>Magento_Customer::group, self, Magento_Customer::admin<\/em> and other rules, instead of <em>anonymous<\/em>.<\/p>\n<p>It is possible to indicate additional parameters as well. For example we need to transfer <em>customer_id<\/em> parameter into the function through the interface.<\/p>\n<p>For that purpose we will write the following between &lt;route&gt;&lt;\/route&gt;:<\/p>\n<pre class=\"lang:php decode:true \">&lt;resources&gt;\r\n    &lt;resource ref=\"self\"\/&gt;\r\n&lt;\/resources&gt;\r\n&lt;data&gt;\r\n    &lt;parameter name=\"customerId\" force=\"true\"&gt;%customer_id%&lt;\/parameter&gt;\r\n&lt;\/data&gt;\r\n<\/pre>\n<p>Thus we should add a parameter in our interface and model, which will receive <em>customer_id<\/em> value.<\/p>\n<p>Api\/TestInterface.php:<\/p>\n<pre class=\"lang:php decode:true\">\/**\r\n* Test function\r\n*\r\n* @api\r\n* @param int $customerId\r\n* @param string $param\r\n* @return string\r\n*\/\r\npublic function test1($customerId, $param);\r\n<\/pre>\n<p>Model\/Test.php:<\/p>\n<pre class=\"lang:php decode:true \">\/**\r\n * Test1 function\r\n *\r\n * @api\r\n * @param int $customerId\r\n * @param string $param\r\n * @return string\r\n *\/\r\n public function test1($customerId, $param) {\r\n return $customerId;\r\n }\r\n<\/pre>\n<p>That&rsquo;s all. We&rsquo;ve just created custom API and now it&rsquo;s ready to use.<\/p>\n<div class=\"module_in_content_container\"><a href=\"https:\/\/belvg.com\/magento-development\" class=\"link_to_module\" target=\"_blank\" rel=\"noopener\"><\/a><div class=\"module_content\"><img src=\"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2015\/12\/magento-development-services.png\" width=\"481\" height=\"480\" alt=\"magento development services\" class=\"module_image\" title=\"How to Create Custom API in Magento 2\"><div class=\"module_content_part\"><h3 class=\"title\">Magento Development Services<\/h3><p class=\"module_content_text\">Take your online store to the next level with BelVG Magento development<\/p><a href=\"https:\/\/belvg.com\/magento-development\" class=\"link_2_to_module\" target=\"_blank\" style=\"display:inline-block\" rel=\"noopener\"><span class=\"read-more\">Click to visit the page<\/span><\/a><\/div><\/div><\/div>\n<p>Looking for an expert&nbsp;<a href=\"https:\/\/belvg.com\/magento-development\" target=\"_blank\" rel=\"noopener\">Magento 2 development team<\/a>? Turn to BelVG!<\/p>\n\n","protected":false},"excerpt":{"rendered":"Today I&#8217;d like to guide you through the process of creating Custom API in Magento &#8230;","protected":false},"author":82,"featured_media":11979,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_acf_changed":false,"footnotes":""},"categories":[14,389,524,462],"tags":[],"class_list":["post-11978","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-magento","category-magento2-development","category-magento-speed-optimization","category-most-popular","post_format-post-format-image"],"acf":[],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"Today I\u2019d like to guide you through the process of creating Custom API in Magento 2. At first we must create the primary files of a module.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Andrey Litvin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-create-custom-api-in-magento-2.html#article\",\"name\":\"How to Create Custom API in Magento 2 | BelVG Blog\",\"headline\":\"How to Create Custom API in Magento 2\",\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrey-litvin#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/11\\\/how-to-create-custom-api.jpg\",\"width\":737,\"height\":200,\"caption\":\"How to Create Custom API in Magento 2\"},\"datePublished\":\"2016-11-24T16:50:19+02:00\",\"dateModified\":\"2021-02-18T14:00:28+02:00\",\"inLanguage\":\"en-US\",\"commentCount\":7,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-create-custom-api-in-magento-2.html#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-create-custom-api-in-magento-2.html#webpage\"},\"articleSection\":\"Magento, Magento 2 Development, Magento Speed Optimization, Most Popular, Image\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-create-custom-api-in-magento-2.html#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"name\":\"Magento\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"position\":2,\"name\":\"Magento\",\"item\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-create-custom-api-in-magento-2.html#listItem\",\"name\":\"How to Create Custom API in Magento 2\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-create-custom-api-in-magento-2.html#listItem\",\"position\":3,\"name\":\"How to Create Custom API in Magento 2\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/category\\\/magento#listItem\",\"name\":\"Magento\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrey-litvin#author\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrey-litvin\",\"name\":\"Andrey Litvin\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-create-custom-api-in-magento-2.html#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e1a6e3c80cb940fddb65016d94b015cd951b4a8a9cd7227565131f28ea95c7a0?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Andrey Litvin\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-create-custom-api-in-magento-2.html#webpage\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-create-custom-api-in-magento-2.html\",\"name\":\"How to Create Custom API in Magento 2 | BelVG Blog\",\"description\":\"Today I\\u2019d like to guide you through the process of creating Custom API in Magento 2. At first we must create the primary files of a module.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-create-custom-api-in-magento-2.html#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrey-litvin#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/author\\\/andrey-litvin#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/11\\\/how-to-create-custom-api.jpg\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-create-custom-api-in-magento-2.html\\\/#mainImage\",\"width\":737,\"height\":200,\"caption\":\"How to Create Custom API in Magento 2\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/how-to-create-custom-api-in-magento-2.html#mainImage\"},\"datePublished\":\"2016-11-24T16:50:19+02:00\",\"dateModified\":\"2021-02-18T14:00:28+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/belvg.com\\\/blog\\\/\",\"name\":\"BelVG Blog\",\"description\":\"Magento and Prestashop articles\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/belvg.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"How to Create Custom API in Magento 2 | BelVG Blog","description":"Today I\u2019d like to guide you through the process of creating Custom API in Magento 2. At first we must create the primary files of a module.","canonical_url":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html#article","name":"How to Create Custom API in Magento 2 | BelVG Blog","headline":"How to Create Custom API in Magento 2","author":{"@id":"https:\/\/belvg.com\/blog\/author\/andrey-litvin#author"},"publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2016\/11\/how-to-create-custom-api.jpg","width":737,"height":200,"caption":"How to Create Custom API in Magento 2"},"datePublished":"2016-11-24T16:50:19+02:00","dateModified":"2021-02-18T14:00:28+02:00","inLanguage":"en-US","commentCount":7,"mainEntityOfPage":{"@id":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html#webpage"},"isPartOf":{"@id":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html#webpage"},"articleSection":"Magento, Magento 2 Development, Magento Speed Optimization, Most Popular, Image"},{"@type":"BreadcrumbList","@id":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","position":1,"name":"Home","item":"https:\/\/belvg.com\/blog\/","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","name":"Magento"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","position":2,"name":"Magento","item":"https:\/\/belvg.com\/blog\/category\/magento","nextItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html#listItem","name":"How to Create Custom API in Magento 2"},"previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html#listItem","position":3,"name":"How to Create Custom API in Magento 2","previousItem":{"@type":"ListItem","@id":"https:\/\/belvg.com\/blog\/category\/magento#listItem","name":"Magento"}}]},{"@type":"Organization","@id":"https:\/\/belvg.com\/blog\/#organization","name":"BelVG Blog","description":"Magento and Prestashop articles","url":"https:\/\/belvg.com\/blog\/"},{"@type":"Person","@id":"https:\/\/belvg.com\/blog\/author\/andrey-litvin#author","url":"https:\/\/belvg.com\/blog\/author\/andrey-litvin","name":"Andrey Litvin","image":{"@type":"ImageObject","@id":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/e1a6e3c80cb940fddb65016d94b015cd951b4a8a9cd7227565131f28ea95c7a0?s=96&d=mm&r=g","width":96,"height":96,"caption":"Andrey Litvin"}},{"@type":"WebPage","@id":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html#webpage","url":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html","name":"How to Create Custom API in Magento 2 | BelVG Blog","description":"Today I\u2019d like to guide you through the process of creating Custom API in Magento 2. At first we must create the primary files of a module.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/belvg.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html#breadcrumblist"},"author":{"@id":"https:\/\/belvg.com\/blog\/author\/andrey-litvin#author"},"creator":{"@id":"https:\/\/belvg.com\/blog\/author\/andrey-litvin#author"},"image":{"@type":"ImageObject","url":"https:\/\/belvg.com\/blog\/wp-content\/uploads\/2016\/11\/how-to-create-custom-api.jpg","@id":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html\/#mainImage","width":737,"height":200,"caption":"How to Create Custom API in Magento 2"},"primaryImageOfPage":{"@id":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html#mainImage"},"datePublished":"2016-11-24T16:50:19+02:00","dateModified":"2021-02-18T14:00:28+02:00"},{"@type":"WebSite","@id":"https:\/\/belvg.com\/blog\/#website","url":"https:\/\/belvg.com\/blog\/","name":"BelVG Blog","description":"Magento and Prestashop articles","inLanguage":"en-US","publisher":{"@id":"https:\/\/belvg.com\/blog\/#organization"}}]}},"aioseo_meta_data":{"post_id":"11978","title":"How to Create Custom API in Magento 2 | #site_title","description":"Today I\u2019d like to guide you through the process of creating Custom API in Magento 2. At first we must create the primary files of a module.","keywords":null,"keyphrases":null,"focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_image_url":null,"twitter_title":null,"twitter_description":null,"schema_type":"default","schema_type_options":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null,"created":"2026-11-03 18:37:25","updated":"2026-11-03 18:37:25"},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/belvg.com\/blog\/category\/magento\" title=\"Magento\">Magento<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tHow to Create Custom API in Magento 2\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/belvg.com\/blog\/"},{"label":"Magento","link":"https:\/\/belvg.com\/blog\/category\/magento"},{"label":"How to Create Custom API in Magento 2","link":"https:\/\/belvg.com\/blog\/how-to-create-custom-api-in-magento-2.html"}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/11978","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/users\/82"}],"replies":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/comments?post=11978"}],"version-history":[{"count":-1,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/posts\/11978\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media\/11979"}],"wp:attachment":[{"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/media?parent=11978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/categories?post=11978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/belvg.com\/blog\/wp-json\/wp\/v2\/tags?post=11978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}