{"id":68424,"date":"2016-12-17T16:49:05","date_gmt":"2016-12-17T16:49:05","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=68424"},"modified":"2025-12-29T09:29:42","modified_gmt":"2025-12-29T09:29:42","slug":"magento2-custom-rest-api","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/","title":{"rendered":"Magento 2 API &#8211; Beginners Guide for API development"},"content":{"rendered":"\n<p><strong>Magento 2 API<\/strong> &#8211; Today, we are going to learn how to create rest REST-based API for Magento 2.<\/p>\n\n\n\n<p>I have worked on Magento 1 and found it very difficult to create a REST web API.<\/p>\n\n\n\n<p>But as I was expecting Magento 2 has a very easy way to define your API resources for the module, especially defining routes for Magento API integration.<\/p>\n\n\n\n<p>Also, check <a href=\"https:\/\/webkul.com\/blog\/graphql-implementation-in-magento2\/\">how to create a GraphQL API in Adobe Commerce<\/a><\/p>\n\n\n\n<p>In order to create a REST API, there are certain requirements for Magento API integration :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You need to create an interface in your module&#8217;s API folder.<\/li>\n\n\n\n<li>Then you need to define all the API methods that you want to expose to the web in the interface.<\/li>\n\n\n\n<li>All the methods should have a doc-block.<\/li>\n\n\n\n<li>In the doc-block, @api must be defined<\/li>\n\n\n\n<li>If your method expects parameters, then all the parameters must be defined in the doc-block as @params &lt;type> &lt;param> &lt;description><\/li>\n\n\n\n<li>Return type of the method must be defined as @return &lt;type> &lt;description><\/li>\n\n\n\n<li>Concrete class of the method must be defined, and it should give the definition of all the api methods and should inherit the doc-block.<\/li>\n<\/ul>\n\n\n\n<p>If your api method does not meet any of the above requirements, then the rest api will not work for Magento 2 integration API.<\/p>\n\n\n\n<p>Now, for example, let&#8217;s create a test module named Webkul_TestApi for better understanding :<\/p>\n\n\n\n<p><strong>Create your module composer.json, registration.php, and module.xml files:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\/**\n* Webkul Software.\n*\n* @category Webkul_MpApi\n*\n* @author Webkul\n* @copyright Copyright (c) Webkul Software Private Limited (https:\/\/webkul.com)\n* @license https:\/\/store.webkul.com\/license.html\n*\/\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n    \\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n    &#039;Webkul_TestApi&#039;,\n    __DIR__\n);<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\">{\n    &quot;name&quot;: &quot;webkul\/marketplace-api&quot;,\n    &quot;description&quot;: &quot;Marketplace api for magento2&quot;,\n    &quot;require&quot;: {\n        &quot;php&quot;: &quot;~5.5.0|~5.6.0|~7.0.0&quot;,\n        &quot;magento\/module-config&quot;: &quot;100.0.*&quot;,\n        &quot;magento\/module-store&quot;: &quot;100.0.*&quot;,\n        &quot;magento\/module-checkout&quot;: &quot;100.0.*&quot;,\n        &quot;magento\/module-catalog&quot;: &quot;100.0.*&quot;,\n        &quot;magento\/module-sales&quot;: &quot;100.0.*&quot;,\n        &quot;magento\/module-customer&quot;: &quot;100.0.*&quot;,\n        &quot;magento\/module-payment&quot;: &quot;100.0.*&quot;,\n        &quot;magento\/module-quote&quot;: &quot;100.0.*&quot;,\n        &quot;magento\/module-backend&quot;: &quot;100.0.*&quot;,\n        &quot;magento\/module-directory&quot;: &quot;100.0.*&quot;,\n        &quot;magento\/module-theme&quot;: &quot;100.0.*&quot;,\n        &quot;magento\/framework&quot;: &quot;100.0.*&quot;\n        \n    },\n    &quot;type&quot;: &quot;magento2-module&quot;,\n    &quot;version&quot;: &quot;2.0.0&quot;,\n    &quot;license&quot;: &#091;\n        &quot;proprietary&quot;\n    ],\n    &quot;autoload&quot;: {\n        &quot;files&quot;: &#091;\n            &quot;registration.php&quot;\n        ],\n        &quot;psr-4&quot;: {\n            &quot;Webkul\\\\TestApi\\\\&quot;: &quot;&quot;\n        }\n    }\n}<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Module\/etc\/module.xsd&quot;&gt;\n    &lt;module name=&quot;Webkul_TestApi&quot; \/&gt;\n&lt;\/config&gt;<\/pre>\n\n\n\n<p><strong>Now create TestApiManagementInterface.php file in app\/code\/Webkul\/TestApi\/Api\/ folder:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\nnamespace Webkul\\TestApi\\Api;\n\ninterface TestApiManagementInterface\n{\n    \/**\n     * get test Api data.\n     *\n     * @api\n     *\n     * @param int $id\n     *\n     * @return \\Webkul\\TestApi\\Api\\Data\\TestApiInterface\n     *\/\n    public function getApiData($id);\n}<\/pre>\n\n\n\n<p>The above will define all the api methods you want to expose; all these methods must have a doc-block defined with @api, @param, and @return, else it will not work for Magento 2 integration API.<\/p>\n\n\n\n<p><strong>Now create TestApiManagementInterface implementation file in app\/code\/Webkul\/TestApi\/Model\/Api folder:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\nnamespace Webkul\\TestApi\\Model\\Api;\n\nclass TestApiManagement implements \\Webkul\\TestApi\\Api\\TestApiManagementInterface\n{\n    const SEVERE_ERROR = 0;\n    const SUCCESS = 1;\n    const LOCAL_ERROR = 2;\n\n    protected $_testApiFactory;\n\n    public function __construct(\n        \\Webkul\\TestApi\\Model\\TestApiFactory $testApiFactory\n\n    ) {\n        $this-&gt;_testApiFactory = $testApiFactory;\n    }\n\n    \/**\n     * get test Api data.\n     *\n     * @api\n     *\n     * @param int $id\n     *\n     * @return \\Webkul\\TestApi\\Api\\Data\\TestApiInterface\n     *\/\n    public function getApiData($id)\n    {\n        try {\n            $model = $this-&gt;_testApiFactory\n                -&gt;create();\n\n            if (!$model-&gt;getId()) {\n                throw new \\Magento\\Framework\\Exception\\LocalizedException(\n                    __(&#039;no data found&#039;)\n                );\n            }\n\n            return $model;\n        } catch (\\Magento\\Framework\\Exception\\LocalizedException $e) {\n            $returnArray&#091;&#039;error&#039;] = $e-&gt;getMessage();\n            $returnArray&#091;&#039;status&#039;] = 0;\n            $this-&gt;getJsonResponse(\n                $returnArray\n            );\n        } catch (\\Exception $e) {\n            $this-&gt;createLog($e);\n            $returnArray&#091;&#039;error&#039;] = __(&#039;unable to process request&#039;);\n            $returnArray&#091;&#039;status&#039;] = 2;\n            $this-&gt;getJsonResponse(\n                $returnArray\n            );\n        }\n    }\n}<\/pre>\n\n\n\n<p>As you can see, I have only created one method, getApiData, as it is defined in the interface, its return type is <strong>\\Webkul\\TestApi\\Api\\Data\\TestApiInterface<\/strong> class<\/p>\n\n\n\n<p>So now we have to create this class and its implementation too for api for Magento 2.<\/p>\n\n\n\n<p><strong>Now, create a model TestApi.php inside app\/code\/Webkul\/TestApi\/Model. This is a fake model; it is not connected to any table since it&#8217;s only for testing purposes.<\/strong><\/p>\n\n\n\n<p><strong>I have just defined some setters and getters for some fields.<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\nnamespace Webkul\\TestApi\\Model;\n\n\/**\n * Marketplace Product Model.\n *\n * @method \\Webkul\\Marketplace\\Model\\ResourceModel\\Product _getResource()\n * @method \\Webkul\\Marketplace\\Model\\ResourceModel\\Product getResource()\n *\/\nclass TestApi  implements \\Webkul\\TestApi\\Api\\Data\\TestApiInterface\n{\n    \/**\n     * Get ID.\n     *\n     * @return int\n     *\/\n    public function getId()\n    {\n        return 10;\n    }\n\n    \/**\n     * Set ID.\n     *\n     * @param int $id\n     *\n     * @return \\Webkul\\Marketplace\\Api\\Data\\ProductInterface\n     *\/\n    public function setId($id)\n    {\n    }\n\n    \/**\n     * Get title.\n     *\n     * @return string|null\n     *\/\n    public function getTitle()\n    {\n        return &#039;this is test title&#039;;\n    }\n\n    \/**\n     * Set title.\n     *\n     * @param string $title\n     *\n     * @return \\Webkul\\Marketplace\\Api\\Data\\ProductInterface\n     *\/\n    public function setTitle($title)\n    {\n    }\n\n    \/**\n     * Get desc.\n     *\n     * @return string|null\n     *\/\n    public function getDescription()\n    {\n        return &#039;this is test api description&#039;;\n    }\n\n    \/**\n     * Set Desc.\n     *\n     * @param string $desc\n     *\n     * @return \\Webkul\\Marketplace\\Api\\Data\\ProductInterface\n     *\/\n    public function setDescription($desc)\n    {\n    }\n}<\/pre>\n\n\n\n<p>The above class has getTitle, getDescription, and getId, so we must expect that api for Magento 2 will return these values in the response.<\/p>\n\n\n\n<p><strong>Now, create the interface class for the above implementation in app\/code\/Webkul\/TestApi\/Api\/Data. <\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\/**\n * Webkul Software.\n *\n * @category  Webkul\n *\n * @author    Webkul\n * @copyright Copyright (c) Webkul Software Private Limited (https:\/\/webkul.com)\n * @license   https:\/\/store.webkul.com\/license.html\n *\/\n\nnamespace Webkul\\TestApi\\Api\\Data;\n\n\/**\n * Marketplace product interface.\n *\n * @api\n *\/\ninterface TestApiInterface\n{\n    \/**#@+\n     * Constants for keys of data array. Identical to the name of the getter in snake case\n     *\/\n    const ENTITY_ID = &#039;entity_id&#039;;\n\n    const TITLE = &#039;title&#039;;\n\n    const DESC = &#039;description&#039;;\n    \/**#@-*\/\n\n    \/**\n     * Get ID.\n     *\n     * @return int|null\n     *\/\n    public function getId();\n\n    \/**\n     * Set ID.\n     *\n     * @param int $id\n     *\n     * @return \\Webkul\\Marketplace\\Api\\Data\\ProductInterface\n     *\/\n    public function setId($id);\n\n    \/**\n     * Get title.\n     *\n     * @return string|null\n     *\/\n    public function getTitle();\n\n    \/**\n     * Set title.\n     *\n     * @param string $title\n     *\n     * @return \\Webkul\\Marketplace\\Api\\Data\\ProductInterface\n     *\/\n    public function setTitle($title);\n\n    \/**\n     * Get desc.\n     *\n     * @return string|null\n     *\/\n    public function getDescription();\n\n    \/**\n     * Set Desc.\n     *\n     * @param string $desc\n     *\n     * @return \\Webkul\\Marketplace\\Api\\Data\\ProductInterface\n     *\/\n    public function setDescription($desc);\n}<\/pre>\n\n\n\n<p><strong>Now you need to create &#8220;app\/code\/Webkul\/TestApi\/etc\/di.xml&#8221; file to map interfaces with the concrete classes:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:ObjectManager\/etc\/config.xsd&quot;&gt;\n  &lt;preference for=&quot;Webkul\\TestApi\\Api\\TestApiManagementInterface&quot; type=&quot;Webkul\\TestApi\\Model\\Api\\TestApiManagement&quot; \/&gt;\n    &lt;preference for=&quot;Webkul\\TestApi\\Api\\Data\\TestApiInterface&quot; type=&quot;Webkul\\TestApi\\Model\\TestApi&quot; \/&gt;\n&lt;\/config&gt;<\/pre>\n\n\n\n<p><strong>Now, create a webapi.xml file inside app\/code\/Webkul\/TestApi\/etc folder:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n\n&lt;routes xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot;\n        xsi:noNamespaceSchemaLocation=&quot;urn:magento:module:Magento_Webapi:etc\/webapi.xsd&quot;&gt;\n    &lt;!-- test api Group --&gt;\n    &lt;route url=&quot;\/V1\/testapi\/custom\/me&quot; method=&quot;GET&quot;&gt;\n        &lt;service class=&quot;Webkul\\TestApi\\Api\\TestApiManagementInterface&quot; method=&quot;getApiData&quot;\/&gt;\n        &lt;resources&gt;\n            &lt;resource ref=&quot;self&quot;\/&gt;\n        &lt;\/resources&gt;\n        &lt;data&gt;\n            &lt;parameter name=&quot;id&quot; force=&quot;true&quot;&gt;%customer_id%&lt;\/parameter&gt;\n        &lt;\/data&gt;\n    &lt;\/route&gt;\n&lt;\/routes&gt;<\/pre>\n\n\n\n<p>The above XML file defines the routes and their permissions.<br><strong>The route tag attributes<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Attribute url defines the route for the web service<\/li>\n\n\n\n<li>Attribute method defines the method GET, PUT, POST, or DELETE<\/li>\n<\/ul>\n\n\n\n<p><strong>Now the service tag attributes:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Class attribute is the interface class that defines the api methods.<\/li>\n\n\n\n<li>\u00a0The service attribute defines the exposed method<\/li>\n<\/ul>\n\n\n\n<p><strong>Now the resource tag defines the access control. These can be three levels of access:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u00a0Admin: For admin-level access, you need to define an admin resource in the resource tag.<\/li>\n\n\n\n<li>Customer: For customer-level access, you need to set yourself up in the resource.<\/li>\n\n\n\n<li>Guest: For guest-level resources, you need to define anonymous in the resource tag.<\/li>\n\n\n\n<li>I have defined self, so this resource will work for customer-level access.<\/li>\n<\/ul>\n\n\n\n<p><strong>This is the PHP file that you can create in your project to access the api resource <\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\nsession_start();\n\/*\n *  base url of the magento host\n *\/\n$host = &#039;http:\/\/magentohost&#039;;\n\n\/\/unset($_SESSION&#091;&#039;access_token&#039;]);\nif (!isset($_SESSION&#091;&#039;access_token&#039;])) {\n    echo &#039;Authenticating...&lt;br&gt;&#039;;\n     \/*\n     * authentication details of the customer\n     *\/\n    $username = &#039;test@webkul.com&#039;;\n    $password = &#039;Admin123&#039;;\n    $postData&#091;&#039;username&#039;] = $username;\n    $postData&#091;&#039;password&#039;] = $password;\n\n    \/*\n     * init curl\n     *\/\n    $ch = curl_init();\n    curl_setopt($ch, CURLOPT_URL, $host.&#039;rest\/V1\/integration\/customer\/token&#039;);\n    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n    \/*\n     * set content type and length\n     *\/\n    curl_setopt($ch, CURLOPT_HTTPHEADER, array(\n            &#039;Content-Type: application\/json&#039;,\n            &#039;Content-Length: &#039;.strlen(json_encode($postData)),\n        )\n    );\n    \/*\n     * setpost data\n     *\/\n    curl_setopt($ch, CURLOPT_POST, count($postData));\n    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));\n    $output = curl_exec($ch);\n    curl_close($ch);\n    \/*\n     * access token in json format\n     *\/\n    echo $output;\n    $_SESSION&#091;&#039;access_token&#039;] = $output;\n}\n    if (isset($_SESSION&#091;&#039;access_token&#039;])) {\n        \/*\n        * create headers for authorization\n        *\/\n        $headers = array(\n            &#039;Authorization: Bearer &#039;.json_decode($_SESSION&#091;&#039;access_token&#039;]),\n        );\n        echo &#039;&lt;pre&gt;&#039;;\n        echo &#039;api call... with key: &#039;.$_SESSION&#091;&#039;access_token&#039;].&#039;&lt;br&gt;&lt;br&gt;&lt;br&gt;&#039;;\n        $ch = curl_init();\n        \/*\n        * set api resource url\n        *\/\n        curl_setopt($ch, CURLOPT_URL, $host.&#039;rest\/V1\/testapi\/custom\/me&#039;);\n        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers\n    );\n        $output = curl_exec($ch);\n        curl_close($ch);\n        echo &#039;&lt;br&gt;&#039;;\n        \/*\n         * json response need to rtrim with &#091;], some times it is appended to the respose so the json becomes invalid so need to rtrim the response\n        *\/\n        $test = json_decode(rtrim($output, &#039;&#091;]&#039;));\n        echo &#039;\n        =========================RESPONSE================================&lt;br&gt;\n        &#039;;\n\n        print_r($test);\n    }\nexit(0);<\/pre>\n\n\n\n<p><strong>In the above file, I have used token-based authentication. Adobe Commerce provides 3 ways to access api resources :<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>1:Token based authentication<\/li>\n\n\n\n<li>2: OAUTH-based authentication<\/li>\n\n\n\n<li>3: Session-Based Authentication<\/li>\n<\/ul>\n\n\n\n<p>You can learn more about it on Adobe Commerce api docs. They have defined it very well:<\/p>\n\n\n\n<p><a href=\"http:\/\/devdocs.magento.com\/guides\/v2.0\/get-started\/authentication\/gs-authentication-token.html\">http:\/\/devdocs.magento.com\/guides\/v2.0\/get-started\/authentication\/gs-authentication-token.html<\/a><\/p>\n\n\n\n<p>This is the response, taken from Postman. You can see the below response returns all the getters from the TestApi model in JSON format, that&#8217;s the beauty of the Magento api.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft\"><img decoding=\"async\" width=\"1049\" height=\"608\" src=\"http:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/rest-api-response.png\" alt=\"rest-api-response\" class=\"wp-image-68430\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/rest-api-response.png 1049w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/rest-api-response-250x145.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/rest-api-response-300x174.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/12\/rest-api-response-768x445.png 768w\" sizes=\"(max-width: 1049px) 100vw, 1049px\" loading=\"lazy\" \/><\/figure>\n<\/div>\n\n\n<p>That&#8217;s all, thanks for reading the article, if you have any queries regarding the blog, please comment below.<\/p>\n\n\n\n<p>If you need technical assistance, please reach out to us at\u00a0<a href=\"mailto:support@webkul.com\">support@webkul.com<\/a>. Additionally, discover various solutions to improve your online store by visiting the\u00a0<a href=\"https:\/\/store.webkul.com\/Magento-2.html\">Adobe Commerce modules<\/a>\u00a0section.<\/p>\n\n\n\n<p>For professional advice or to create custom functionalities, consider hiring&nbsp;<a href=\"https:\/\/webkul.com\/hire-magento-developers\/\">Adobe Commerce Developers<\/a>&nbsp;for your project.<br>Thanks \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 API &#8211; Today, we are going to learn how to create rest REST-based API for Magento 2. I have worked on Magento 1 and found it very difficult to create a REST web API. But as I was expecting Magento 2 has a very easy way to define your API resources for the <a href=\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":33,"featured_media":65964,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[4200,4199,291,4201],"class_list":["post-68424","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","tag-custom-rest-api","tag-magento2-rest","tag-rest","tag-standard-rest"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento 2 API \u2013 Beginners Guide for API development<\/title>\n<meta name=\"description\" content=\"Learn the basics of Magento 2 API development with this beginner-friendly guide covering REST, SOAP, authentication, and custom API creation.\" \/>\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\/magento2-custom-rest-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento 2 API \u2013 Beginners Guide for API development\" \/>\n<meta property=\"og:description\" content=\"Learn the basics of Magento 2 API development with this beginner-friendly guide covering REST, SOAP, authentication, and custom API creation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/\" \/>\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=\"2016-12-17T16:49:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-12-29T09:29:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-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=\"Ashutosh Srivastava\" \/>\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=\"Ashutosh Srivastava\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/\"},\"author\":{\"name\":\"Ashutosh Srivastava\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970\"},\"headline\":\"Magento 2 API &#8211; Beginners Guide for API development\",\"datePublished\":\"2016-12-17T16:49:05+00:00\",\"dateModified\":\"2025-12-29T09:29:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/\"},\"wordCount\":753,\"commentCount\":31,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet-1.png\",\"keywords\":[\"custom rest api\",\"magento2 rest\",\"rest\",\"standard rest\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/\",\"url\":\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/\",\"name\":\"Magento 2 API \u2013 Beginners Guide for API development\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet-1.png\",\"datePublished\":\"2016-12-17T16:49:05+00:00\",\"dateModified\":\"2025-12-29T09:29:42+00:00\",\"description\":\"Learn the basics of Magento 2 API development with this beginner-friendly guide covering REST, SOAP, authentication, and custom API creation.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet-1.png\",\"width\":825,\"height\":260},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento 2 API &#8211; Beginners Guide for API development\"}]},{\"@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\/5555025750ec4e4df34fadc78b083970\",\"name\":\"Ashutosh Srivastava\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?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\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Ashutosh Srivastava\"},\"sameAs\":[\"http:\/\/webkul.com\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/ashutosh\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Magento 2 API \u2013 Beginners Guide for API development","description":"Learn the basics of Magento 2 API development with this beginner-friendly guide covering REST, SOAP, authentication, and custom API creation.","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\/magento2-custom-rest-api\/","og_locale":"en_US","og_type":"article","og_title":"Magento 2 API \u2013 Beginners Guide for API development","og_description":"Learn the basics of Magento 2 API development with this beginner-friendly guide covering REST, SOAP, authentication, and custom API creation.","og_url":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-12-17T16:49:05+00:00","article_modified_time":"2025-12-29T09:29:42+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet-1.png","type":"image\/png"}],"author":"Ashutosh Srivastava","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Ashutosh Srivastava","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/"},"author":{"name":"Ashutosh Srivastava","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970"},"headline":"Magento 2 API &#8211; Beginners Guide for API development","datePublished":"2016-12-17T16:49:05+00:00","dateModified":"2025-12-29T09:29:42+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/"},"wordCount":753,"commentCount":31,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet-1.png","keywords":["custom rest api","magento2 rest","rest","standard rest"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/","url":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/","name":"Magento 2 API \u2013 Beginners Guide for API development","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet-1.png","datePublished":"2016-12-17T16:49:05+00:00","dateModified":"2025-12-29T09:29:42+00:00","description":"Learn the basics of Magento 2 API development with this beginner-friendly guide covering REST, SOAP, authentication, and custom API creation.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/11\/Magneto-Code-Snippet-1.png","width":825,"height":260},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/magento2-custom-rest-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento 2 API &#8211; Beginners Guide for API development"}]},{"@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\/5555025750ec4e4df34fadc78b083970","name":"Ashutosh Srivastava","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?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\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Ashutosh Srivastava"},"sameAs":["http:\/\/webkul.com"],"url":"https:\/\/webkul.com\/blog\/author\/ashutosh\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/68424","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\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=68424"}],"version-history":[{"count":23,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/68424\/revisions"}],"predecessor-version":[{"id":519145,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/68424\/revisions\/519145"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/65964"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=68424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=68424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=68424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}