{"id":2281,"date":"2023-08-24T07:00:37","date_gmt":"2023-08-24T07:00:37","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/how-to-test-magento-2-api-in-postman\/"},"modified":"2025-03-17T05:51:57","modified_gmt":"2025-03-17T05:51:57","slug":"how-to-test-magento-2-api-in-postman","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/how-to-test-magento-2-api-in-postman\/","title":{"rendered":"How to Test Magento 2 API in Postman? (With Example)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 (Adobe Commerce) offers an enterprise-level platform for selling online. Its high-end flexibility and integration through REST APIs make it a preferable choice for all businesses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The platform offers built-in web APIs for integration with other apps and services. You can also build a custom REST API and deploy it per your needs. No matter if you\u2019re using the in-built or custom APIs, you\u2019ll need to test them before implementation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, we\u2019ll learn how to\u00a0test Magento 2 APIs\u00a0in Postman with examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"getting-started-with-postman\">Test Magento 2 API \u2013 Getting Started with Postman<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.postman.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Postman<\/a>&nbsp;is an API platform used to build, test, and document APIs. You can download and install the Postman application in your Windows\/Mac from its&nbsp;<a href=\"https:\/\/www.postman.com\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener\">official site<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Or you can use the web version.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create an account and log into the Postman app.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In your workspace, create a new collection to test the Magento 2 APIs. Basically, it is a set of saved APIs; you can also download pre-created collections for various APIs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go to&nbsp;<strong>Collections<\/strong>, click&nbsp;<strong>+<\/strong>&nbsp;button, and name the collection.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2023\/07\/1-create-a-new-collection-in-postman.png\" alt=\"Create a new collection in Postman\" class=\"wp-image-33262\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Now, click Add a request to make an API call under this collection.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2023\/07\/2-add-a-request.png\" alt=\"Add a request in Postman\" class=\"wp-image-33261\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">You can make an API request by filling up various details.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the screenshot below, you can find more information about each of the elements in the Postman request interface.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2023\/07\/3-postman-interface.png\" alt=\"Postman Interface\" class=\"wp-image-33260\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s understand how to test the Magento 2 API in Postman through examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"steps-to-test-magento-2-api\">Steps to Test Magento 2 API<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose we want to test an admin-side Magento 2 API.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You\u2019ll need the admin token to perform any admin-level actions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can get the Magento 2 admin token by passing the credentials via a GET request.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s understand it through an example.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-1-admin-login\">Example #1: Admin Login<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In Postman, create a new POST request and enter the following address:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>store_url\/rest\/V1\/integration\/admin\/token<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the&nbsp;<strong>Headers<\/strong>&nbsp;tab, set&nbsp;<code>Content-Type<\/code>&nbsp;=&nbsp;<code>application\/json<\/code>&nbsp;as shown in the screenshot below.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2023\/07\/4-get-admin-token.png\" alt=\"Get admin toke to test Magento 2 API\" class=\"wp-image-33259\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Now, go to&nbsp;<strong>Body<\/strong>&nbsp;and select raw JSON as the body type.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Enter your admin credentials in the following format:<\/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\"username\": \"enter-your-admin-username\",\n\"password\": \"enter-your-admin-password\"\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Click the&nbsp;<strong>Send<\/strong>&nbsp;button at the top-right corner.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2023\/07\/5-enter-user-name-password.png\" alt=\"Enter username and password\" class=\"wp-image-33258\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">In the response body, you\u2019ll get the admin token, which you can use for making any admin-related API calls in Magento 2.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"example-2-update-product-price\">Example #2: Update Product Price<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s say you want to change product attributes, for e.g., price, using Magento 2 API. You can do this by making a PUT request and passing the SKU of the product.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s how to do it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a new tab or request in Postman. Select PUT as the request type, and enter the following in the address field:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>store_url\/rest\/V1\/products\/{sku_of_the_product}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the&nbsp;<strong>Authorization<\/strong>&nbsp;tab, select&nbsp;<strong>Bearer Token<\/strong>, and enter the admin token in the field.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2023\/07\/6-send-request-to-change-product-price.png\" alt=\"Send Magento 2 API Request\" class=\"wp-image-33257\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">In the&nbsp;<strong>Body<\/strong>&nbsp;select raw JSON as type, and enter the following:<\/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}\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Hit the&nbsp;<strong>Send<\/strong>&nbsp;button.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2023\/07\/7-product-price-changed.png\" alt=\"Test Magento 2 API - Changed price\" class=\"wp-image-33256\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">The response body will return the product details with the updated price! You\u2019ve successfully tested Magento 2 API for admin functions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Similarly, you can test&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/create-custom-rest-api-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">custom Magento 2 APIs<\/a>&nbsp;in Postman before deploying.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"learn-more-about-magento-2-api-integration\">Learn More About Magento 2 API Integration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Postman is an excellent application to build and test Magento 2 API. Try the steps provided above to experiment with API integration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do not forget to check out our&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">ultimate resource for Magento 2 APIs<\/a>. We keep updating the resource page with more custom APIs we develop over time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 (Adobe Commerce) offers an enterprise-level platform for selling online. Its high-end flexibility and integration through REST APIs make it a preferable choice for&#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-2281","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2281","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=2281"}],"version-history":[{"count":1,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2281\/revisions"}],"predecessor-version":[{"id":5115,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2281\/revisions\/5115"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=2281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=2281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=2281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}