I need to know for each product sky, price and stock. I am using[filter_groups][0][filters][0][field]=category_id&searchCriteria[filter_groups][0][filters][0][value]=1&searchCriteria[filter_groups][0][filters][0][condition_type]=eq

In the web documentation I see that I can get it


"stockItem": {
          "itemId": 0,
          "productId": 0,
          "stockId": 0,
          "qty": 0,
          "isInStock": true,
          "isQtyDecimal": true,
          "showDefaultNotificationMessage": true,
          "useConfigMinQty": true,
          "minQty": 0,
          "useConfigMinSaleQty": 0,
          "minSaleQty": 0,
          "useConfigMaxSaleQty": true,
          "maxSaleQty": 0,
          "useConfigBackorders": true,
          "backorders": 0,
          "useConfigNotifyStockQty": true,
          "notifyStockQty": 0,
          "useConfigQtyIncrements": true,
          "qtyIncrements": 0,
          "useConfigEnableQtyInc": true,
          "enableQtyIncrements": true,
          "useConfigManageStock": true,
          "manageStock": true,
          "lowStockDate": "string",
          "isDecimalDivided": true,
          "stockStatusChangedAuto": 0,
          "extensionAttributes": {}

But when I use it does not appear that information, why?


I did it this way, i hope this helps you:

$api = new Api();
$ch = curl_init();
$data = array("username" => "{your_username}", "password" => "{your_pw}");
$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data_string))
$qty = $_GET["qty"];
$sku = $_GET["sku"];

//you need to replace this with your own code for token
$token = $api->GetToken($ch,$data_string);

$headers = array("Authorization: Bearer $token");
$requestUrl='https://example.com/index.php/rest/V1/stockItems/' . $sku;

//See method "GetProductAsObject" below
$product = $api->GetProductAsObject($sku,$ch,$requestUrl,$headers);


$toencode["stockItem"] = $product;

//This part will print your desired result
echo json_encode($toencode);

//#### Info: this method is in a separate class ###
//This method is in the Class Api.php known as $api above
public function GetProductAsObject($sku,$ch,$requestUrl,$headers)
     $ch = curl_init();
     $ch = curl_init($requestUrl);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

     $result = curl_exec($ch);
     return json_decode($result);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.