How to Test Magento 2 API in Postman? (With Example)
Magento Integration Made Easy!
Integrate any third-party tool or service with your store using our Magento API Integration Services.
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.
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’re using the in-built or custom APIs, you’ll need to test them before implementation.
In this post, we’ll learn how to test Magento 2 APIs in Postman with examples.
Table of Contents
- Test Magento 2 API – Getting Started with Postman
- Steps to Test Magento 2 API
- Learn More About Magento 2 API Integration
Test Magento 2 API – Getting Started with Postman
Postman 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 official site.
Or you can use the web version.
Create an account and log into the Postman app.
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.
Go to Collections, click + button, and name the collection.
Now, click Add a request to make an API call under this collection.
You can make an API request by filling up various details.
In the screenshot below, you can find more information about each of the elements in the Postman request interface.
Let’s understand how to test the Magento 2 API in Postman through examples.
Steps to Test Magento 2 API
Suppose we want to test an admin-side Magento 2 API.
You’ll need the admin token to perform any admin-level actions.
You can get the Magento 2 admin token by passing the credentials via a GET request.
Let’s understand it through an example.
Example #1: Admin Login
In Postman, create a new POST request and enter the following address:
store_url/rest/V1/integration/admin/token
In the Headers tab, set Content-Type
= application/json
as shown in the screenshot below.
Now, go to Body and select raw JSON as the body type.
Enter your admin credentials in the following format:
{
"username": "enter-your-admin-username",
"password": "enter-your-admin-password"
}
Click the Send button at the top-right corner.
In the response body, you’ll get the admin token, which you can use for making any admin-related API calls in Magento 2.
Example #2: Update Product Price
Let’s 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.
Here’s how to do it.
Create a new tab or request in Postman. Select PUT as the request type, and enter the following in the address field:
store_url/rest/V1/products/{sku_of_the_product}
In the Authorization tab, select Bearer Token, and enter the admin token in the field.
In the Body select raw JSON as type, and enter the following:
{
"product": {
"price": 20000
}
}
Hit the Send button.
The response body will return the product details with the updated price! You’ve successfully tested Magento 2 API for admin functions.
Similarly, you can test custom Magento 2 APIs in Postman before deploying.
Learn More About Magento 2 API Integration
Postman is an excellent application to build and test Magento 2 API. Try the steps provided above to experiment with API integration.
Do not forget to check out our ultimate resource for Magento 2 APIs. We keep updating the resource page with more custom APIs we develop over time.
Thank you!
Related article:
Connect your Magento store with any third-party tool or service & improve your business efficiency.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
Ecommerce Mobile App Development: What Is It & Best Companies
Learn How to Get Logged In Customer Address in Magento 2
Next