Create product using REST API programmatically in magento 2.

For Access Magento 2 REST API, you need to first generate an access token. Access token used for synchronization with Magento to other third-party platforms. Check the link for Generate Access Token Magento 2

Once you got the Access Token for Magento, You can call REST API for creating a product from a third-party system.

You can create a simple product from a third party platform by just calling Magento REST API without touching the Magento backend.

You can programmatically create a simple product by just below code,

Action Type: POST

Request URL:  <YOUR_SITE_URL>/rest/V1/products

Header:  For Header, You need to pass an array for headers,
‘Content-Type:application/json’,’Authorization:Bearer ‘.$accessToken’

Where $accessToken is your site Access Token.

In the above Request, We have created a simple product in Magento 2, Pass the required data to create a simple product.  Using the above data, We can create a simple product with name equals to Test Product 1.

You can set price, SKU, visibility, weight, type_id, status, and all the other attribute and custom field using REST API.

When Run above script code, You can create a simple product in Magento 2 successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *