{"id":1126,"date":"2020-07-18T03:30:32","date_gmt":"2020-07-18T03:30:32","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/07\/18\/create-update-product-using-rest-api-in-magento-2\/"},"modified":"2025-05-22T12:09:48","modified_gmt":"2025-05-22T06:39:48","slug":"create-update-product-using-rest-api-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/create-update-product-using-rest-api-in-magento-2\/","title":{"rendered":"How to Create &#038; Update Product Using REST API in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Are you following the ERP model of business for Magento 2 store?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ever had the requirement to manage the changes in ERP to directly reflect in the Magento 2 online store?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If yes, you can consider this post as the starting point for you where I am giving the solution to&nbsp;create &amp; update&nbsp;product&nbsp;using API in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also refer to the&nbsp;<a href=\"https:\/\/developer.adobe.com\/commerce\/webapi\/rest\/\" target=\"_blank\" rel=\"noreferrer noopener\">official document<\/a>&nbsp;for starters,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u201cA software interface that lets third-party applications read and write to a system using programming language constructs or statements.\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Magento supports and provides&nbsp;<a href=\"https:\/\/developer.adobe.com\/commerce\/docs\/\" target=\"_blank\" rel=\"noreferrer noopener\">REST<\/a>&nbsp;and&nbsp;<a href=\"https:\/\/developer.adobe.com\/commerce\/docs\/\" target=\"_blank\" rel=\"noreferrer noopener\">SOAP<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Magento uses&nbsp;<a href=\"https:\/\/swagger.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">Swagger<\/a>&nbsp;to display REST APIs for all installed products and allows you to try out the APIs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 REST API<\/a>&nbsp;identifies various functions&nbsp;to perform requests and receive responses. One can perform these interactions by using the HTTP protocol.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to create &amp; update product using API in Magento 2:<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Method to create product using API in Magento 2:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First, you need to generate an authentication key and follow the below steps for the same:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Navigate to&nbsp;<strong>System &gt; Extensions &gt; Integration<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Click&nbsp;<strong>Add New Integration<\/strong>&nbsp;button<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Enter your&nbsp;<strong>Name<\/strong>&nbsp;and&nbsp;<strong>admin Password<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2020\/07\/1_create-product-using-API-in-Magento-2.png\" alt=\"1_create-product-using-API-in-Magento-2\" class=\"wp-image-9734\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">4. Click&nbsp;<strong>save<\/strong>&nbsp;and&nbsp;<strong>active<\/strong>&nbsp;button<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5. Click&nbsp;<strong>Allow<\/strong>. Now the Authentication key is generated<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2020\/07\/2_create-product-using-API-in-Magento-2.png\" alt=\"2_create product using API in Magento 2\" class=\"wp-image-9735\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>New API<\/strong>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2020\/07\/new-api.png\" alt=\"new api\" class=\"wp-image-9736\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>New Auth:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2020\/07\/new-auth.png\" alt=\"new auth\" class=\"wp-image-9737\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">First you need to open swagger like &lt;YourBaseURL&gt;\/Swagger\/# or open list of API&nbsp;<strong>https:\/\/devdocs.magento.com\/swagger\/#\/<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In order to create and update product in Magento 2, you may require to generate admin access token first. Read here&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-get-admin-token\/\" target=\"_blank\" rel=\"noreferrer noopener\">how to get admin token in Magento 2 API<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open Postman and enter URL to create the product:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>&nbsp;&lt;YourbaseURL&gt;\/rest\/\/V1\/products eg. http:\/\/127.0.0.1\/magento\/rest\/V1\/products<\/li>\n\n\n\n<li>Select Method Post<\/li>\n\n\n\n<li>Header part :Authorization: Bearer &lt;Hear Enter generated Authentication key&gt;<br>Content-Type: &nbsp; application\/json<\/li>\n\n\n\n<li>Enter payload data into body section<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"product\": {\n    \"sku\": \"samsung-a50\",\n    \"name\": \"Samsung A50 \",\n    \"attribute_set_id\": 4,\n    \"price\": 150000,\n    \"status\": 1,\n    \"visibility\": 1,\n    \"type_id\": \"Default\",\n    \"weight\": \"1\",\n    \"extension_attributes\": {\n      \"category_links\": [\n        {\n          \"position\": 0,\n          \"category_id\": \"6\"\n        }\n      ],\n      \"stock_item\": {\n        \"qty\": \"10\",\n        \"is_in_stock\": true\n      }\n    },\n    \"custom_attributes\": [\n      {\n        \"attribute_code\": \"pattern\",\n        \"value\": \"1960\"\n      },\n      {\n        \"attribute_code\": \"color\",\n        \"value\": \"45\"\n      },\n      {\n        \"attribute_code\": \"size\",\n        \"value\": \"168\"\n      }\n    ]\n  }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Method to Update Product Using API in Magento 2:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">URL: &nbsp;&lt;BaseURL&gt;\/rest\/V1\/products\/{SKU} &nbsp;eg. http:\/\/127.0.0.1\/magento\/rest\/V1\/products\/samsung-a50<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Select Method : PUT<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Body<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"product\": {\n    \"price\": 20000,\n    \"custom_attributes\": [\n      {\n        \"attribute_code\": \"color\",\n        \"value\": \"47\"\n      }\n    ]\n  }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First, you need to open swagger like &lt;YourBaseURL&gt;\/Swagger\/# or open list of API https:\/\/devdocs.magento.com\/swagger\/#\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It would be great if you could share the post with Magento 2 developers via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you following the ERP model of business for Magento 2 store? Ever had the requirement to manage the changes in ERP to directly reflect&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1126","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1126"}],"version-history":[{"count":7,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1126\/revisions"}],"predecessor-version":[{"id":14783,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1126\/revisions\/14783"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}