How to generate schema for Magento2 API and import to Postman

Yaroslav Voronoy
2 min readFeb 20, 2017

--

The Magento2 API framework provides an easy way to communicate with Magento platform. It allows to create separate applications, integrations with 3rd party services, or use it for developing purpose to automate routine stuff like creating products, orders, merchants, etc.

Every time when I used to API for tests I had to recall how to prepare and make request, which parameters and endpoints should I use. And I have found Postman which covers all needed functionality for testing API. Postman allows to import Magento API schema and it simplifies any API call. You just select needed endpoint and make request.

How to generate Magento2 API schema

Postman allows you to import schema in json format. To generate the schema make request to URL http://m2.host/index.php/rest/default/schema. It will show you schema with anonymous access to resources. To get complete schema you should make request with authorization header and save result in file. See example below.

curl -X POST "http://m2.host/index.php/rest/V1/integration/admin/token" \
-H "Content-Type:application/json" \
-d '{"username":"admin", "password":"your-password"}'
curl -X POST http://m2.host/index.php/rest/default/schema \
-H "Authorization: Bearer idcfdipbei9ydpoobgns7tl0uhvaur10" > magento2.api.schema.json

Import magento2.api.schema.json file into postman by pressing Import button and select Import File. And you will get complete schema to all resources.

Let try to create product. Find endpoint PUT http://m2.host/rest/default/V1/products/:sku.

Add Authorization header into headers section. You can save authorization token into presets to use it for other requests.

{
"product": {
"attribute_set_id": 4,
"sku": "000100",
"name": "Simplest Product",
"price": 25.00,
"status": 1,
"type_id": "simple",
"custom_attributes": {
"description": "A Very Simple Product",
"meta_description": "A Very Simple Product"
}
}
}

You will get new created product.

--

--

Yaroslav Voronoy

Magento Developer at @Magento Inc. Certified Magento Developer. #realmagento #magento #magento2 https://github.com/yvoronoy