Update item variable quantity through API?

J Kenneth

Is it possible to update the quantity of an existing item variable through the API? 

Comments

5 comments

  • Comment author
    Chris Muench

    This is now possible in the latest 17.7 release. 

    0
  • Comment author
    J Kenneth

    The quantity field for a variation item is in locations-x-variations-quantity?

    0
  • Comment author
    Chris Muench

    Yes

    0
  • Comment author
    J Kenneth

    Hi Chris,

    I am having trouble. It is showing an API call but none of my items quantities are being updated. 

    $data = array('locations'=> array(
            1 => array( 
                'variations' => array(
                    0 => array(
                        'quantity' => 8
                    )
                )
            )
        )
    );
    0
  • Comment author
    Chris Muench
    • Edited

    Here is a working code example. Make sure you know the item_id and variation_id

    <?php

    //////////////////////////////////////////////////////////

    $api_base_url = 'http://localhost/phppos/PHP-Point-Of-Sale/index.php/api/v1/';

    $api_key = '8ooosck0sc0w8g0gk48g044c4cokkgc8kwk8sk08';

    ///////////////////////////////////////////////////////////

    $item_id = 1;
    $item_variation_id = 2;

    $post_data = array('locations' => 
    array("1" => array('variations' => 
    array(
    array('variation_id' => $item_variation_id,'quantity' => 1000))
    )
    ));



    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $api_base_url.'items/'.$item_id);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
        'x-api-key:'.$api_key,
    'accept: application/json',

        ));

    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl,CURLOPT_POST, 1);
    curl_setopt($curl,CURLOPT_POSTFIELDS, json_encode($post_data));

    $result = json_decode(curl_exec($curl), TRUE);
    echo '<pre>';
    var_dump($result);
    echo '</pre>';
    0

Please sign in to leave a comment.