How to return all sold items in inventory

meatcomputermeatcomputer Posts: 23Member

Hey all,

what's the best api call to get me all sold items in my inventory?

All the best ,

Wouter

4 comments

  • meatcomputermeatcomputer Posts: 23Member

    is it not possible to do this?

  • Adrian SamuelAdrian Samuel Posts: 474Moderator, Lightspeed Staff moderator
    edited April 9

    Hey @meatcomputer, great question!

    The easiest way to do this would be to loop through your inventory and grab all the itemIDs and then programmatically pass it in as a search parameter into the sale endpoint like so

    https://api.lightspeedapp.com/API/{{accountID}}/Sale.json?load_relations=["SaleLines"]&SaleLines.itemID={{itemID}}

    Then you'd check if the ["@attributes"].count is greater than 0. Then you'll know if that item has been sold before.

    Hope this helps!

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

  • meatcomputermeatcomputer Posts: 23Member

    @Adrian Samuel Thanks for the answer. That api request url doesn't seem to be working though. I input a valid account id, a valid itemid from a product that has sales. and I get the same error, regardless of what the itemid is.

    The error is

    '{"httpCode":"404","httpMessage":"Not Found","message":"Control \'182174.Sale\' could not be found.","errorClass":"InvalidControlError"}'

    and its always 182174.Sale regaurdless of what I put in for the item_id

  • Adrian SamuelAdrian Samuel Posts: 474Moderator, Lightspeed Staff moderator

    Hey @meatcomputer thanks for pointing this out, it's me to blame here, I made a typo and left out Account from the request path.

    All API requests have a base structure like so:

    https://api.lightspeedapp.com/API/Account/{{accountID}}/{{endpoint}}.[json/xml]?{{queryParameters}}

    https://api.lightspeedapp.com/API/Account/{{accountID}}/Sale.json?load_relations=["SaleLines"]&SaleLines.itemID={{itemID}}

    You should find that the above works :)

    Adrian Samuel

    API Integrations Consultant - Strategic Solutions

    Lightspeed HQ

Sign In or Register to comment.