cancel
Showing results for 
Search instead for 
Did you mean: 

create or update product simple programmatically in magento2

create or update product simple programmatically in magento2

Hi,

Kan iemand mij helpen? ik krijg een foutmelding: 

[message] => Group price must be a number greater than 0.

 

<?php
$url= "https://localhost/index.php/rest";
$accessToken= "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$setHeaders = array('Content-Type:application/json','Authorization:Bearer '.$accessToken);

$url = $url."/V1/products/24-UG04";
$apiUrl = str_replace(" ","%20",$url);

$data = [
"product" => [
"visibility" => 4,
"status" =>1,
"price" => 86.95,
"tierPrices" => [
"price_type" => "fixed",
"website_id" => 0,
"customer_group" => "General",
"price" => 30.00,
"quantity" => 5
]
]
];

$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $setHeaders);
$token = curl_exec($ch);

$response = json_decode( curl_exec($ch), TRUE);
curl_close($ch);
echo "<pre>";print_r($response);exit;

?>

1 REPLY 1

Re: create or update product simple programmatically in magento2

On this screen you can see the structure of tier price: https://prnt.sc/o7esqv

If you work on Magento 2.3 then read this swagger https://localhost/swagger, it will help you to test up integration

Also it is a good guide

https://devdocs.magento.com/guides/v2.3/rest/generate-local.html

 

E-commerce specialist working on Magento Platform, developing custom extension, providing midrations and website optimizations.Also handling tasks of website development.