I'm trying to access the REST Endpoints:
POST /V1/products/special-price
POST /V1/products/special-price-information
POST /V1/products/special-price-delete
I want to achieve this through PHP code however i'm finding it hard to understand just how to access them. I want to be able to GET the special prices of specific products. Any direction would be a help.
-
you can get special price like magento.stackexchange.com/a/195709Hitesh– Hitesh2018年11月23日 09:48:12 +00:00Commented Nov 23, 2018 at 9:48
1 Answer 1
Try below code.
$url="http://localhost/magento/index.php/";
$tokenUrl=$url."rest/V1/integration/admin/token";
$productSpecialUrl=$url. "rest/V1/products/special-price";
$username="admin";
$password="password";
//get admin access token
$ch = curl_init();
$data = array("username" => $username, "password" => $password);
$dataString = json_encode($data);
$ch = curl_init($tokenUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$token = curl_exec($ch);
$requestPayload = json_encode(array(array('price' => 100, 'store_id' => 1, 'sku' => 'sku123', 'price_from' => date, 'price_to' => date )));
$ch = curl_init($productSpecialUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestPayload);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));
$result = curl_exec($ch);
$result = json_decode($result, 1);
echo '<pre>';print_r($result);
Let me know if you need further help.
answered Nov 23, 2018 at 9:47
Ramkishan Suthar
4,0526 gold badges36 silver badges56 bronze badges
default