2

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.

asked Nov 23, 2018 at 9:37
1

1 Answer 1

3

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.