Basic API Questions

Hi there, Im very new to the coding world and even newer to API usage so please pardon my newbie questions but I've hit a point where I need some guidance. I'm writing an integration for Google Sheets and using the Apps Script editor to make the calls. here are the 2 immediate questions i have.
Q1: I am trying to retrieve a sales report of all the sales for a particular store & register. We have 5 stores each with 1 register on the account. I'm not sure how to structure the endpoints accordingly.
Q2: Can I request specific fields from each sales line only ?
I know that there is load_relations only im not entirely sure if that's the means in which to get the fields or if I use that after the sale.json? to load the [salelines]?
I have the Oauth2 protocol working fine Im just not finding many examples where sales are used as most use items as the endpoint. Which reminds me in many javascript object {} examples there is the term "items" used to reference the values with in an object array. Is that a valid term to use when calling the sales lines given that there are actual "items" to be considered with in the sales lines? "
I appreciate any help, references and suggestions that are offered as well as your time and attention replying to this . I have my code up on my Github should you wish to have a look. and while I've messed with it a bit its close to the most recent version, Thanks again!
Q1: I am trying to retrieve a sales report of all the sales for a particular store & register. We have 5 stores each with 1 register on the account. I'm not sure how to structure the endpoints accordingly.
Q2: Can I request specific fields from each sales line only ?
I know that there is load_relations only im not entirely sure if that's the means in which to get the fields or if I use that after the sale.json? to load the [salelines]?
https://api.lightspeedapp.com/API/Account/166476/Sale?load_relations=["SaleLines.Item"]&completeTime=><,2018-07-24T00:00:00-0500,2018-08-14T00:00:00-0500
I have the Oauth2 protocol working fine Im just not finding many examples where sales are used as most use items as the endpoint. Which reminds me in many javascript object {} examples there is the term "items" used to reference the values with in an object array. Is that a valid term to use when calling the sales lines given that there are actual "items" to be considered with in the sales lines? "
I appreciate any help, references and suggestions that are offered as well as your time and attention replying to this . I have my code up on my Github should you wish to have a look. and while I've messed with it a bit its close to the most recent version, Thanks again!
Post edited by LiquidLuke on
Much thanks for everyone's help!
15 comments
1. You can use the shopID as your query string to only display sales from a specific store. Making a GET request to the Shop endpoint will provide the shopID of each one of your shops.
2. You can load multiple relations (Note each endpoint has unique relations). In order to load the SaleLines to the Sale endpoint use the SaleLines relations (GET /API/Account/{accountID}/Sale.json?load_relation=["SaleLines"].
API Support Specialist
Lightspeed HQ
https://api.lightspeedapp.com/API/Account/Account ID/Shop/4/Sale.json?load_relations=["SaleLines.Item"]
You can use the shopID and registerID as query strings in your request.
API Support Specialist
Lightspeed HQ
Execution failed: Invalid argument: https://api.lightspeedapp.com/API/Account/myAccountID/Sale.json?load_relations=["SaleLines"]&shopID=4®isterID=6 (line 39, file "Code") [1.175 seconds total runtime]
ANy thoughts as to where i got it wrong? (I do have my correct Account ID in the Query)The query works fine when I run it, Would it be possible to get a copy of the error message?
API Support Specialist
Lightspeed HQ
Q1: how do I specify the fields I want to return as I find I am usually only ever after a few specific fields?
And..
Q2: looking at the API docs I can load relations SaleLines to the Sale end point as you mentioned above and on the Sale page it's noted as a relation and then there is a returned field SaleLine type={Object}. Is the information returned from this the same as the end point Saleline? I ask only to use the SaleLine endpoint doc page as a guide to see what fields may be included so I can populate the headers in my google Sheet to match the results to.
It seems stupidly obvious but I have a habit of assuming to much so I'm asking just to be sure.
Again thank you for your time on this.
Q1: You can't control which fields are returned.
Q2: Yes, you're right, you can (and should)use the SaleLine endpoint as a reference for the SaleLine objects that you load as a relation on the Sale endpoint. The SaleLines will look the same.
Lightspeed HQ
/API/Account/My_Account_ID/Customer/Customer ID.json?load_relations=["CustomFieldValues"]
One thing I would recommend if you are looking for reporting data, that doesn't have to be near real-time. What I wound up doing was to export paginated record sets afterhours. Ported these to a local SQL DB. That way I could provide me endusers the data pot for them to draw from. Different reports, different parameters, different options, etc. they could choose. But just hitting my SQL DB. That way they wouldn't notice any performance penalties, I could introduce different angles in terms of table joins, etc.
Besides that isn't a way to query for specific Custom field values without first making a request and sorting the data yourself from there.
Adrian Samuel
API Integrations Consultant - Strategic Solutions
Lightspeed HQ
I'm sure I'll have more questions soon thank you both for the help!
I had it going but rejigged my code to accept more options and somewhere along the line I seem to have forgotten whats needed. ANy thoughts?