Creating Products using Magento API

In this article, we will use the Magento eCommerce POST API to create a product with Postman.

Prem Singh Rathore
3 min readSep 8, 2021
Image source: Google

What is Magento APIs❓

Magento API is a framework that offers developers and integrators a good method to maximize web services that communicate well with the Magneto system.

The URI we are gonna need to create the product is.

https://MagentoHost/rest/V1/products

Note: Your website URL will come in place of Magento Host.

The payload body, which we will send along with the request.

{"product": {"sku": "256478945148","name": "Sample Product","attribute_set_id": "4","price": "250","status": "1","visibility": "4","type_id": "simple","weight": "1","extension_attributes": {"category_links": [{"position": "0","category_id": "6"}],"stock_item": {"qty": "50","is_in_stock": true}},"custom_attributes": [{  "attribute_code": "express_delivery_product",  "value": "1"},{  "attribute_code": "is_grocery_product",  "value": "0"}]}}

Note: The custom attributes are based on the product attributes defined in the backend.

Also, we need to set the content type to JSON format in the header section.

Content-Type : application/json

Finally, the authorization key, which you need to get from the backend.

Image source: Google

Select Bearer Token option under the Authorization Tab and provide the Access Token.

Authorization Tab

Now, you hit the send button and wait for the response.

{"id": 62,"sku": "256478945148","name": "Sample Product","attribute_set_id": 4,"price": 250,"status": 1,"visibility": 4,"type_id": "simple","created_at": "2021-09-08 12:54:59","updated_at": "2021-09-08 12:54:59","weight": 1,"extension_attributes": {"website_ids": [1],"category_links": [{"position": 0,"category_id": "6"}],"stock_item": {"item_id": 232,"product_id": 62,"stock_id": 1,"qty": 50,"is_in_stock": true,"is_qty_decimal": false,"show_default_notification_message": false,"use_config_min_qty": true,"min_qty": 0,"use_config_min_sale_qty": 1,"min_sale_qty": 1,"use_config_max_sale_qty": true,"max_sale_qty": 10000,"use_config_backorders": true,"backorders": 0,"use_config_notify_stock_qty": true,"notify_stock_qty": 1,"use_config_qty_increments": true,"qty_increments": 0,"use_config_enable_qty_inc": true,"enable_qty_increments": false,"use_config_manage_stock": true,"manage_stock": true,"low_stock_date": null,"is_decimal_divided": false,"stock_status_changed_auto": 0}},"options": [],"media_gallery_entries": [],"custom_attributes": [{"attribute_code": "url_key","value": "sample-product"},{"attribute_code": "options_container","value": "container2"},{"attribute_code": "brands","value": "21"},{"attribute_code": "msrp_display_actual_price_type","value": "0"},{"attribute_code": "required_options","value": "0"},{"attribute_code": "has_options","value": "0"},{"attribute_code": "tax_class_id","value": "2"},{"attribute_code": "category_ids","value": ["6"]},{"attribute_code": "is_returnable","value": "2"},{"attribute_code": "stock_check","value": "3"},{"attribute_code": "express_delivery_product","value": "1"},{"attribute_code": "is_grocery_product","value": "0"},{"attribute_code": "amtoolkit_robots","value": "0"},{"attribute_code": "am_offer_item_condition","value": "1"}]}

And, Here is the Magento demo server for you to play with.

Thanks for reading.

--

--