Item Quantity with Item.json API

tops_123tops_123 Member Posts: 22

Hello,

How can I get quantity of Items in

GET /API/Account/{accountID}/Item.json

Thanks

28 comments

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 299 moderator
    edited May 12

    Hi @tops_123,

    Thank you for reaching out to us.

    To get the QOH of the item you can use this parameter:

    GET /Item?load_relations=["ItemShops"]

    I hope this helps.

  • tops_123tops_123 Member Posts: 22

    https://api.lightspeedapp.com/API/Account/221693/Item?load_relations=['ItemShops']

    I am not getting any result on this call.


    Can you explain whats wrong with the call ?

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 299 moderator

    Hi

    Are you getting an error message?

  • tops_123tops_123 Member Posts: 22

    No actually it is not returning any result.

    Just empty result

    Thanks

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 299 moderator

    Are you getting any result when you're doing /Item.json ?

  • tops_123tops_123 Member Posts: 22

    https://api.lightspeedapp.com/API/Account/221693/Item.json?load_relations=['ItemShops'] :- Not working

    https://api.lightspeedapp.com/API/Account/221693/Item?load_relations=['ItemShops'] :- Not working

    https://api.lightspeedapp.com/API/Account/221693/Item.json :- Working good


    Array
    (
        [@attributes] => Array
            (
                [count] => 1
                [offset] => 0
                [limit] => 100
            )
    
        [Item] => Array
            (
                [itemID] => 1
                [systemSku] => 210000000001
                [defaultCost] => 400
                [avgCost] => 400
                [discountable] => true
                [tax] => true
                [archived] => false
                [itemType] => serialized
                [serialized] => true
                [description] => Iphone 6
                [modelYear] => 0
                [upc] => 121001121001
                [ean] => 1210011210011
                [customSku] => 12345678
                [manufacturerSku] => 
                [createTime] => 2020-05-06T10:12:24+00:00
                [timeStamp] => 2020-05-11T09:09:13+00:00
                [categoryID] => 0
                [taxClassID] => 1
                [departmentID] => 0
                [itemMatrixID] => 0
                [manufacturerID] => 1
                [seasonID] => 0
                [defaultVendorID] => 1
                [Prices] => Array
                    (
                        [ItemPrice] => Array
                            (
                                [0] => Array
                                    (
                                        [amount] => 400
                                        [useTypeID] => 1
                                        [useType] => Default
                                    )
    
                                [1] => Array
                                    (
                                        [amount] => 400
                                        [useTypeID] => 2
                                        [useType] => MSRP
                                    )
    
                                [2] => Array
                                    (
                                        [amount] => 400
                                        [useTypeID] => 3
                                        [useType] => Online
                                    )
    
                            )
    
                    )
    
            )
    
    )
    

    See in above result i want Quantity also per item

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 299 moderator

    Please use double quotes, like in my example:

    /Item.json?load_relations=["ItemShops"]
    
  • tops_123tops_123 Member Posts: 22

    Thanks it worked.

    I have a question why itemShop is displaying 2 result of same product

  • tops_123tops_123 Member Posts: 22
  • tops_123tops_123 Member Posts: 22

    Hello ?

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 299 moderator

    Very nice, that it's working now.

    ItemShop with shopID = 0 is a summary record that includes the QOH for all shops.

    I hope this helps.

  • tops_123tops_123 Member Posts: 22

    Thank you so much!

    Ok means it will return the total quantity of item in all the shop.

  • tops_123tops_123 Member Posts: 22

    Please ignore my stupid questions as I am new to Lightspeed and need to integrate these apis

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 299 moderator

    You're welcome! This is correct.

    You can read more info about this here.

  • tops_123tops_123 Member Posts: 22

    Thanks. I am reading this page from last 2 hours :D

    And example to update they have in shell language not in php. Is there any example where i can see and update the inventory through api

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 299 moderator

    No problem at all, that's why we're here for. Maybe other people have the same problem with this, I hope this make things more clear now.

  • tops_123tops_123 Member Posts: 22

    Yes its really helping me out. As i have to make my senior explain about the same.

  • tops_123tops_123 Member Posts: 22

    How can i update the item using api in php. As in overview only shell language example is shown

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 299 moderator

    You can do this for example like this:

    <?php
    $client = new http\Client;
    $request = new http\Client\Request;
    $request->setRequestUrl('{{base_url}}/API/Account/{{accountID}}/Item/{{ItemID}}.json');
    $request->setRequestMethod('PUT');
    $body = new http\Message\Body;
    $body->append('{
    	"description": "My new discription"
    }');
    $request->setBody($body);
    $request->setOptions(array());
    $request->setHeaders(array(
      'Authorization' => 'Bearer {{token}}',
      'Content-Type' => 'application/json'
    ));
    $client->enqueue($request)->send();
    $response = $client->getResponse();
    echo $response->getBody();
    
  • tops_123tops_123 Member Posts: 22

    Thank you sir.. :)

  • tops_123tops_123 Member Posts: 22

    How can i update the quantity of the item.

    i am able to update the description using


    $postfields = array(

     'description' => 'I Phone 6 New'

      

    );


    $postfields = json_encode($postfields);

    But quantity is not updated using the same

  • tops_123tops_123 Member Posts: 22

    Hello any idea about updating the quantity of an item ?

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 299 moderator
    edited May 12

    I've tested it in Postman with this payload and it worked:

    "description": "My new discription",
    	"ItemShops": {
                    "ItemShop": [
                        {
                        "itemShopID": "222",
                        "qoh": "20",
                        "itemID": "7",
                        "shopID": "2"
                    }
                  ]
    	}
    
  • tops_123tops_123 Member Posts: 22

    okay thanks. let me try this same

  • tops_123tops_123 Member Posts: 22

    Thanks it work


    [ItemShops] => Array
                            (
                                [ItemShop] => Array
                                    (
                                        [0] => Array
                                            (
                                                [itemShopID] => 2
                                                [qoh] => 1
                                                [sellable] => 1
                                                [backorder] => 0
                                                [componentQoh] => 0
                                                [componentBackorder] => 0
                                                [reorderPoint] => 5
                                                [reorderLevel] => 0
                                                [timeStamp] => 2020-05-11T09:08:59+00:00
                                                [itemID] => 1
                                                [shopID] => 1
                                            )
    
                                        [1] => Array
                                            (
                                                [itemShopID] => 1
                                                [qoh] => 1
                                                [sellable] => 1
                                                [backorder] => 0
                                                [componentQoh] => 0
                                                [componentBackorder] => 0
                                                [reorderPoint] => 0
                                                [reorderLevel] => 0
                                                [timeStamp] => 2020-05-06T10:12:24+00:00
                                                [itemID] => 1
                                                [shopID] => 0
                                            )
    
                                    )
    
                            )
    
    qoh is the field used for quantity thanks.
    

    I

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 299 moderator

    @tops_123,

    Perfect!

  • thisconnectthisconnect Member Posts: 13

    hi,

    when i update the qoh with a negative number, i get the error:

    'qoh' must be a positive integer.

    but the client uses negative stock in Retail...

    can this be fixed?

    thx

  • LucienVersendaalLucienVersendaal Moderator, Lightspeed Staff Posts: 299 moderator

    Hi @thisconnect,

    I'm checking with our devs.

Sign In or Register to comment.