{"id":45217,"date":"2016-04-08T07:41:56","date_gmt":"2016-04-08T07:41:56","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=45217"},"modified":"2016-04-13T09:28:05","modified_gmt":"2016-04-13T09:28:05","slug":"magento2-rest-api","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/magento2-rest-api\/","title":{"rendered":"Magento2 REST API"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>Magento2 REST\u00a0API \u2013 Magento is best open-source e-commerce tool which is written in PHP. Magento recently upgraded version\u00a0<strong>1.x<\/strong> to\u00a0<strong>2.0<\/strong>\u00a0which is officially released and when you run Magento 2.0 then you will be feel like &#8220;ooooo shiny new toy&#8221;.<\/p>\n<p><strong>REST\u00a0integration in Magento2<\/strong>\u00a0is \u201cSimply Easy\u201d. Magento provides a very simple REST\u00a0API integration.<\/p>\n<ul>\n<li>Go to\u00a0<strong>Magento System\u00a0-&gt;\u00a0<strong class=\"submenu-group-title\">Permissions<\/strong> -&gt;\u00a0User Roles<\/strong>\u00a0and add a simple rule over there lets say \u201cWebKul\u201d.<\/li>\n<li>Go to\u00a0<strong>Magento\u00a0<strong>System<\/strong> -&gt;<strong><strong class=\"submenu-group-title\">Permissions<\/strong><\/strong> -&gt;\u00a0All Users<\/strong>\u00a0and add a new user or you can use existing user with the detailed info most important fact is to set the\u00a0<strong>permission of user to all instead of custom.\u00a0<\/strong>Lets assume\u00a0user is &#8220;admin&#8221;.<\/li>\n<li>Create a py\u00a0file outside the magento and add the sample code.<\/li>\n<\/ul>\n<pre class=\"brush:py\">import xmlrpclib\r\nimport json\r\nimport requests\r\n\r\n##################For Token Based Authentication#################\r\nurl = 'http:\/\/domain\/index.php\/rest\/V1\/integration\/admin\/token'\r\ncredentials = {\r\n\"username\": \"admin\",\r\n\"password\": \"webkul\"\r\n}\r\ncredentials = json.dumps(credentials)\r\nheaders = {'Content-Type' : 'application\/json'}\r\nresponse = requests.post(url,  data=credentials,  headers=headers)\r\n#############################HTTP Status Code &lt;200&gt; will assure you about successful connection ############\r\nprint response<\/pre>\n<ul>\n<li class=\"brush:py\">To check response use &#8220;.text&#8221; for example: response.text .<\/li>\n<li class=\"brush:py\">You specify the token in the Authorization request header with the Bearer HTTP authorization scheme.\n<pre class=\"brush:py\">token = \"Bearer \" + json.loads((response.text))<\/pre>\n<\/li>\n<li class=\"brush:py\">Now fetch list of Magento websites using token based authentication.\n<pre class=\"brush:py\">store_view_url = 'http:\/\/domain\/index.php\/rest\/V1\/store\/websites'\r\nheaders = {'Authorization':token, 'Content-Type':'application\/json'}\r\nmagento_websites = requests.get(store_view_url, headers=headers)\r\nmagento_websites = json.loads(magento_websites)\r\n<\/pre>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Magento2 REST\u00a0API \u2013 Magento is best open-source e-commerce tool which is written in PHP. Magento recently upgraded version\u00a01.x to\u00a02.0\u00a0which is officially released and when you run Magento 2.0 then you will be feel like &#8220;ooooo shiny new toy&#8221;. REST\u00a0integration in Magento2\u00a0is \u201cSimply Easy\u201d. Magento provides a very simple REST\u00a0API integration. Go to\u00a0Magento System\u00a0-&gt;\u00a0Permissions -&gt;\u00a0User <a href=\"https:\/\/webkul.com\/blog\/magento2-rest-api\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":90,"featured_media":43620,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[2070,2954,2253],"class_list":["post-45217","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","tag-magento2","tag-magento2-api","tag-rest-api"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Magento2 REST API - Webkul Blog<\/title>\n<meta name=\"description\" content=\"Magento2 has very powerful rest api which allows us to access its data from outside, now in this blog you see how to connect your magento2 with rest api.\" \/>\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-rest-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Magento2 REST API - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Magento2 has very powerful rest api which allows us to access its data from outside, now in this blog you see how to connect your magento2 with rest api.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/magento2-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-04-08T07:41:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-04-13T09:28:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/03\/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=\"Ashish Singh\" \/>\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=\"Ashish Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-rest-api\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-rest-api\/\"},\"author\":{\"name\":\"Ashish Singh\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/3b92c698256ce0bcb9613acf8bbf5b2d\"},\"headline\":\"Magento2 REST API\",\"datePublished\":\"2016-04-08T07:41:56+00:00\",\"dateModified\":\"2016-04-13T09:28:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-rest-api\/\"},\"wordCount\":171,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-rest-api\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/03\/Magneto-Code-Snippet-1.png\",\"keywords\":[\"Magento2\",\"magento2 api\",\"REST API\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/magento2-rest-api\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-rest-api\/\",\"url\":\"https:\/\/webkul.com\/blog\/magento2-rest-api\/\",\"name\":\"Magento2 REST API - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-rest-api\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-rest-api\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/03\/Magneto-Code-Snippet-1.png\",\"datePublished\":\"2016-04-08T07:41:56+00:00\",\"dateModified\":\"2016-04-13T09:28:05+00:00\",\"description\":\"Magento2 has very powerful rest api which allows us to access its data from outside, now in this blog you see how to connect your magento2 with rest api.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/magento2-rest-api\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/magento2-rest-api\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-rest-api\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/03\/Magneto-Code-Snippet-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/03\/Magneto-Code-Snippet-1.png\",\"width\":825,\"height\":260},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/magento2-rest-api\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento2 REST API\"}]},{\"@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\/3b92c698256ce0bcb9613acf8bbf5b2d\",\"name\":\"Ashish Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ef2c82640f6054d8a8cfca9e3edd7edaf800ff1873b6d103c7bbf0b47dfefc1e?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\/ef2c82640f6054d8a8cfca9e3edd7edaf800ff1873b6d103c7bbf0b47dfefc1e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Ashish Singh\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/ashish067\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Magento2 REST API - Webkul Blog","description":"Magento2 has very powerful rest api which allows us to access its data from outside, now in this blog you see how to connect your magento2 with rest api.","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-rest-api\/","og_locale":"en_US","og_type":"article","og_title":"Magento2 REST API - Webkul Blog","og_description":"Magento2 has very powerful rest api which allows us to access its data from outside, now in this blog you see how to connect your magento2 with rest api.","og_url":"https:\/\/webkul.com\/blog\/magento2-rest-api\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-04-08T07:41:56+00:00","article_modified_time":"2016-04-13T09:28:05+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/03\/Magneto-Code-Snippet-1.png","type":"image\/png"}],"author":"Ashish Singh","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Ashish Singh","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/magento2-rest-api\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/magento2-rest-api\/"},"author":{"name":"Ashish Singh","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/3b92c698256ce0bcb9613acf8bbf5b2d"},"headline":"Magento2 REST API","datePublished":"2016-04-08T07:41:56+00:00","dateModified":"2016-04-13T09:28:05+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento2-rest-api\/"},"wordCount":171,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento2-rest-api\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/03\/Magneto-Code-Snippet-1.png","keywords":["Magento2","magento2 api","REST API"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/magento2-rest-api\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/magento2-rest-api\/","url":"https:\/\/webkul.com\/blog\/magento2-rest-api\/","name":"Magento2 REST API - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/magento2-rest-api\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/magento2-rest-api\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/03\/Magneto-Code-Snippet-1.png","datePublished":"2016-04-08T07:41:56+00:00","dateModified":"2016-04-13T09:28:05+00:00","description":"Magento2 has very powerful rest api which allows us to access its data from outside, now in this blog you see how to connect your magento2 with rest api.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/magento2-rest-api\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/magento2-rest-api\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/magento2-rest-api\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/03\/Magneto-Code-Snippet-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/03\/Magneto-Code-Snippet-1.png","width":825,"height":260},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/magento2-rest-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento2 REST API"}]},{"@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\/3b92c698256ce0bcb9613acf8bbf5b2d","name":"Ashish Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ef2c82640f6054d8a8cfca9e3edd7edaf800ff1873b6d103c7bbf0b47dfefc1e?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\/ef2c82640f6054d8a8cfca9e3edd7edaf800ff1873b6d103c7bbf0b47dfefc1e?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Ashish Singh"},"url":"https:\/\/webkul.com\/blog\/author\/ashish067\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/45217","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\/90"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=45217"}],"version-history":[{"count":9,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/45217\/revisions"}],"predecessor-version":[{"id":45783,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/45217\/revisions\/45783"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/43620"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=45217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=45217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=45217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}