0
$ch = curl_init("92.19.109.89/index.php/rest/V1/products/".$productId);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));
$result = curl_exec($ch);
//var_dump(curl_getinfo($ch));
$result = json_decode($result, 1);

How to add data field ?

1 Answer 1

1

You can replace your site url instead of http://127.0.0.1/testmagento.

    <?php
    $productData = '{
        "product": {
        "extension_attributes": {
          "stock_item": {
            "qty": "20",
            "is_in_stock": true
          }
        }
        }
        }';

$url = "http://127.0.0.1/testmagento/index.php/rest/all/V1/products/t-shirt";
$token = "8mc3cad6dsc0ce74m1kyfn7iyvbpc7a7";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $productData);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " .$token));
    $result = json_decode(curl_exec($ch));
    print_r($result);
    exit();
    ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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