API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

How to: REST PUT to update a product?

Hello, I am using CURL/PHP with the REST API.
I'm trying to update product data, and keep receiveing bool(false) from the server.
My code is below. Can you lend some extra eyes to help me figure out what's wrong?
function economicQueryPutCurl($url, $jsonData)
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://restapi.e-conomic.com" . $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER,
        'X-AppSecretToken' => '___',
        'X-AgreementGrantToken' => '___',
        'Content-Type: application/json; charset=utf-8',
        'Content-Length: ' . strlen($jsonData)
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    $response  = curl_exec($ch);
    return $response;
function economicUpdateProduct()
    $sku = "999-999-9999";
    $data = array(
        "productNumber" => $sku,
        "name" => "My Product",
        "productGroup" => array(
            "productGroupNumber" => "40",
    return economicQueryPutCurl(urlencode("/products/".$sku), json_encode($data));
created Dec 12, 2016 by nicholas
0% Accept Rate
Q 1 A 0 C 1

1 Answer

Hi Nicholas,

The REST service will never return "false". In case you're reaching the service we'll be responding with a full document.
Perhaps some of the other users on the forum can shed some light on whether the cURL usage looks correct?
answered Dec 12, 2016 by olej
Hi Olej,
Got it working by rewriting the PHP part (pasted below).
Are the weight properties in "inventory" readonly?
In the schema it indicates they should be writable but they aren't updating, but the other properties are.

function economicPerform($method, $path, $data = null)
    $url = "https://restapi.e-conomic.com" . $path;
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HEADER, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    if (0 == strcmp(strtoupper($method), 'PUT')) {
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($curl, CURLOPT_HTTPHEADER,
        'X-AgreementGrantToken: ______',
    $data = curl_exec($curl);
    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    $success = (200 <= $status)&&($status < 300);
    $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
    $header = substr($data , 0, $headerSize);
    $body = substr($data, $headerSize);
    return ["url"=>$url, "success"=> $success, "status"=>$status, "data"=>json_decode($body)];

$response = economicPerform("GET", "/products/999-999-9999");
$object = $response["data"];
$object->description = "New Description"; // WORKS
$object->inventory->packageVolume = 2.5; // WORKS
$object->inventory->netWeight = 2.5; // DOESN'T WORK
economicPerform("PUT", "/products/999-999-9999", $object)
Visma e-conomic A/S