Skip to content

How create product programatically with product ProductRepository and Json

I am trying to add product programatically with json format which we can used create product through API but unable to create product.

$json = '{
"sku": "samsung-a50",
"name": "Samsung A50 ",
"attribute_set_id": 4,
"price": 150000,
"status": 1,
"visibility": 1,
"type_id": "Default",
"weight": "1"
}'; 
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productObj = $objectManager->create("MagentoCatalogModelProductRepository"); 
$productData = $objectManager->create("MagentoCatalogApiDataProductInterface");
$productData->setData($json);
$productObj->save($productData);

Can you please help to create product with ProductRepository which we used in API format

Actually i want create product with json to achieve multiple products create with single API request