How do I call inventory that's available per store?

thisisbolothisisbolo Member Posts: 26
I'm trying to do the following. I have 3 stores and I need 3 separate calls from each store that'll return the following:

Items w/ Inventory
System ID
Manufact. SKU
ID (Vendor)
In Stock

Is this possible? What should the PHP file look like with the right headers and URL?
Super Cat Lightspeed


  • thisisbolothisisbolo Member Posts: 26
    Ok, I ran this and checked the response but there's some of the above missing so I think it has to do with the load_relations. I also noticed I only get a response of 100 items. How do I call all the inventory that's only in stock at 1 of the stores?


    $curl = curl_init();

    curl_setopt_array($curl, array(
      CURLOPT_URL => "{accountID}/Item.json?load_relations=%5B%22ItemShops%22%5D&ItemShops.timeStamp=%3E%2C2017-11-10T12%3A00%3A00Z",
      CURLOPT_TIMEOUT => 30,
      CURLOPT_HTTPHEADER => array(
        "authorization: Bearer {Access Token}"

    $response = curl_exec($curl);
    $err = curl_error($curl);


    if ($err) {
        echo "cURL Error #:" . $err;
    } else {
        echo $response;

    Super Cat Lightspeed
  • thisisbolothisisbolo Member Posts: 26
    I also tried load_relations=all and I still don't get all fields

    Items w/ Inventory
    System ID
    Manufact. SKU
    ID (Vendor)
    In Stock
    Super Cat Lightspeed
  • Adrian SamuelAdrian Samuel Moderator, Lightspeed Staff Posts: 625 moderator
    edited October 2018
    @thisisbolo it looks like you've been able to figure out most of the things yourself.

    load_relations=all does in fact return all the required data objects but we would advise you shorten your query to:{{accountID}}/Item?load_relations=["ItemShops", "ItemVendorNums"];
    This would give you the relevant results.

    SystemID is called systemSku in the API
    UPC, EAN are called exactly that although they are lowercase
    Manufact. SKU is called manufacturerSku in the API

    The vendor information is contained in the "ItemVendorNums" object. It returns a vendorID. You'll need to make a seperate request with that vendorID to the Vendor endpoint for the vendor name. More information about that can be read here:
    If your app however has the vendor ID associated with the vendor names, you will save yourself an extra call.

    The "ItemShops" object gives all the detail about the quantity on hand of a given item per shop. The object key is called "qoh". You can determine whether an item is in stock or not by creating a boolean test to see whether the quantity on hand/qoh is greater than zero.

    As to how to get all items, the API limits each request to returning 100 objects. To a seperate page you'll have to append an offset to the query

    an example of this would be:{{accountID}}/Item?load_relations=["ItemShops", "ItemVendorNums"]&offset=100;

    Every GET request will return an attributes object
    an example one can be found here:

     "@attributes": {        "count": "296",        "offset": "100",        "limit": "100"

    ["@attributes"].count =  How many objects in total // Answer = 296
    ["@attributes"].offset = Which page i'm on. You "offset" a page of objects by setting the offset to be "previous number" + 100 at a time.
    ["@attributes"].limit = How many objects you want to limit the response to return. It can be less than 100 but is 100 by default.

    If I wanted to loop through every page I might do this:
    - Divide the count by 100 (because 100 objects are returned by default)

    ["@attributes"].count/100 = 2.96
    An offset of 0 will return objects 1-100
    An offset of 100 will return objects 101- 200
    An offset of 200 will return objects 201-296

    So I am going through page 1 (offset 0), 2 (offset 100) & 3 (offset 200)

    I will therefore want to round up my 2.96 to the next integer which would be 3

    If I was to write a for loop in javascript I might do this

    for( let i = 0; i < 3; i++) {{{AccountId}}/Item.json?load_relations=["ItemShops", "ItemVendorNums"]&offset=i*100;

    As we have initialised i as 0
    the calculation of the offset will be as follows:
    Loop 1 = 0 x 100 =  0
    Loop 2 = 1 x 100 = 100
    Loop 3 = 2 x 100 = 200
    Loop 4 won't execute since i will equal 3 and 3 is not less than 3.
    Storing that data in an array/ your database will enable your to manipulate the data and do what you need to do with it.

    I hope this helps!

    Adrian Samuel

    Integrations & Solutions Developer - Strategic Solutions

    Lightspeed HQ

  • thisisbolothisisbolo Member Posts: 26
    Thank you Adrian. Just one other question, how do I return under 'Inventory Defaults', there's Default Cost, Vendor, and ID.

    This ID number seems to be attached to the vendor's own sku for product. This is what I'd like to pull.

    Super Cat Lightspeed
  • thisisbolothisisbolo Member Posts: 26
    I think I found it

    Super Cat Lightspeed
  • thisisbolothisisbolo Member Posts: 26
    I think?
    Super Cat Lightspeed
Sign In or Register to comment.