Using the API to retrieve sales data

jcaprajcapra Member Posts: 4
edited September 2017 in Development
Hello LightSpeed Onsiters!

Can we talk API? How can I achieve the same result as running a Sales Report on a Single Product through the API?

That's it! Thanks!

1 comment

  • jamesratcliffejamesratcliffe Administrator, Lightspeed Staff Posts: 160 moderator
    Hi James,

    The Invoice search endpoint can find you all the Invoices (for a specific date range) that have a given product on them:
    POST /api/invoices/search/

    <search>
    <search_query>
    <columns>
    <column id="lsserver.search.column.id"/>
    </columns>
    <filters>lsserver.search.filters.product_id = 'P-1003' AND lsserver.search.filters.created_date > '2017-10-01'</filters>
    </search_query>
    </search>
    You can add more columns, but the available columns relate to the invoice itself and not the line items.

    The response will be something like this:
    <?xml version="1.0" encoding="utf-8"?>
    <data>
    <info>
    <total_count>1</total_count>
    </info>
    <columns>
    <column>
    <name>
    <localizable_message type="lsserver.search.column.id">
    <fields/>
    <plain_message>ID</plain_message>
    </localizable_message>
    </name>
    <type>STRING</type>
    </column>
    </columns>
    <rows>
    <row>
    <links>
    <link>
    <invoice uri="https://localhost:9630/api/invoices/54/" id="54"/>
    </link>
    </links>
    <cell>
    <type>STRING</type>
    <value>I-54</value>
    </cell>
    </row>
    </rows>
    </data>
    You can then get the invoice line items from each invoice, take the ones that have the product on them, then format them into a report.
    James Ratcliffe
    Lightspeed HQ
Sign In or Register to comment.