Shopfy REST API inventory level set (and adjust) does not work

LucaCalabrese1
New Member
1 0 0

Hello I am usind PHP curl in order to manage my inventory with Shopify.

Everthing workd fine except for inventory levels. For example:

 

    $url = "https://app:pwd@url.myshopify.com/admin/api/2021-10/inventory_levels/set.json";
    $data_json=json_encode(
        array(
            "inventory_levels/set" => array(
                "location_id" => $idlocation,
                "inventory_item_id" => $invitem,
                "available" => $qty
            ) 
        ),  
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json))); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch); 
    curl_close($ch);
    
    var_dump($response);

 

I am pretty sure $idlocation, $qty and $invitem are valid real data, I verified that $invitem is an actual integer representing an id of an inventory_item_id.

The response I get (even trying with different approachs) is:

string(72) "{"errors":{"inventory_item_id":"Required parameter missing or invalid"}}"

What does it mean? And how I do pass a valid parameter?

Replies 0 (0)