Passing Data After a Retail & E commerce Sale?

scott74scott74 Posts: 35Member
I am looking to pass a data after each sale is made into a 3rd party reputation marketing system.

Data needed would be:

  1. Customer First Name
  2. Customer Email
  3. Customer Cell Phone
  4. Store Location Whether That Be An ID of some sort
  5. Employee Name That Made The Sale

Looking to set this up through Zapier but did't see anywhere in light speed to add a web-hook after a sales is made.

Can anyone point me in the right direction to accomplish this and would these be separate API's for E commerce and Retail Sale?

Thanks Scott
<1

37 comments

  • gregaricangregarican Posts: 239Member 
    I'm not sure that LS Retail has webhooks of any sort in the API. Although LS E-com does if I'm not mistaken. If anyone on here wants to correct me if I'm mistaken :smiley:
  • scott74scott74 Posts: 35Member
    Thanks, Can I create a polling URL in Zapier to ping Light Speed for a new Sales and pass that info that way?

    Just looking for that documentation and what all data can be passed after the sale.. Just needing the above 5 bullets basically.

    Thanks for the help.
  • scott74scott74 Posts: 35Member
    Thank you. I will play around with it. Can you tell me where I find my account ID?

    https://api.lightspeedapp.com//API/Account/{accountID}/Sale/{saleID}
  • gregaricangregarican Posts: 239Member 
    In LS Retail, click on Help down in the bottom left. The Account ID appears in the little pop-up window!
  • Adrian SamuelAdrian Samuel Posts: 413Moderator, Lightspeed Staff moderator
    edited November 2018
    @gregarican great responses!

    @scott74 , as Greg has said you could set up a chron job to dynamically get sales data since Retail doesn't have webhooks

    Also you can get your accountID from the account endpoint here: 
    https://developers.lightspeedhq.com/retail/endpoints/Account/
  • scott74scott74 Posts: 35Member
    edited November 2018
    Ok thanks Adrian.
    Looks like that requires a token. I only saw something in my account with tokens when I enabled ecom. Do I have this with the retail side to connect to the API?

    I had signed up for a trial account to test this but wondering if you have another way of testing for agencies seeing what they might be able to do for clients or best way to go about that? My trial is 14 days and have one of my guys who is a little better with the API stuff look at this.

    Another option is if you guys have SFTP where you can generate a list of fields and a URL to send that to each day. Is that possible with the system?
    Post edited by scott74 on
  • Adrian SamuelAdrian Samuel Posts: 413Moderator, Lightspeed Staff moderator
    Hey @scott74, yeah you'll need to register an API client and then go through the steps as listed in the documentation to get your access token:

    https://developers.lightspeedhq.com/retail/authentication/authentication-overview/

    If you login to your account could simply pass the API URL in the browser. Something like this:
    https://us.lightspeedapp.com/API/Account/{{accountID}}/{{endpoint}}.json

    We don't have a SFTP but you can just use the API to replicate the same process.


  • scott74scott74 Posts: 35Member
    Thanks.... Anyway to go about keeping a demo account open to test this? My trial expired and still working with a developer to see if he can help set this up.

    Not looking to use this for myself, just a demo account to setup integrations for future clients who use this system.

    Thanks, Scott
  • Adrian SamuelAdrian Samuel Posts: 413Moderator, Lightspeed Staff moderator
    @scott74 could you private message me your accountID 
  • scott74scott74 Posts: 35Member
    Just sent... Thanks
  • Adrian SamuelAdrian Samuel Posts: 413Moderator, Lightspeed Staff moderator
    @scott74 the website url can be the localhost or the link to a website that connects with your app

    The redirect URI will be the page that Lightspeed will redirect you to send the access token once you authenticate your account with the app. If you're in testing you could use https://localhost otherwise you want to use the hosted IP/domain that your app is associated to

    An example of this can be found here:  https://developers.lightspeedhq.com/retail/authentication/authentication-overview/#requesting-a-temporary-token
  • scott74scott74 Posts: 35Member
    edited December 2018
    Thanks..got token working but How do you keep it from expiring?

    I used the Employee:all scope but wondering which permissions would be needed just to pull the register name, customer data and employee that made the sale for scopes instead of using all. This way if the correct way is sending the client a link it doesn't show as full access. Or is it best they make you a user on the account temporarily ?

    Post edited by scott74 on
  • scott74scott74 Posts: 35Member
    @scott74 the website url can be the localhost or the link to a website that connects with your app

    The redirect URI will be the page that Lightspeed will redirect you to send the access token once you authenticate your account with the app. If you're in testing you could use https://localhost otherwise you want to use the hosted IP/domain that your app is associated to

    An example of this can be found here:  https://developers.lightspeedhq.com/retail/authentication/authentication-overview/#requesting-a-temporary-token
    I planned on setting this up in zapier so still a little confused on what URL's you would use. We would not be have any website associated, just using to pass customer data after a sale through zapier.

    I have setup a test in postman using local host and just used my agency domain for the first URL. Just trying to get a grip on what I need to do if making this work live for a client and how to go about creating it for them if I need to login their account as a user or create these apps in my account. Please advise 
  • scott74scott74 Posts: 35Member
    edited December 2018
    I recall looking at Zapier awhile back. But didn't dig into it too deeply.

    A sender could ping LS Retail's API to pull recent sales. Based on a polling period against a timestamp of the sale in LS Retail. Here's a link to the LS Retail Sales API --> https://developers.lightspeedhq.com/retail/endpoints/Sale/.

    You would likely need to sort the sales in descending createTime order, and could restrict the createTime to a range within your polling period that makes sense. And you also would need to load_relations if you need to include additional data fields apart from the general sales data set. The employee and customer contact details come to mind there.

    Hope this helps a little at least!
    Thanks bud.....   I used this and grabbed the customer contact details

    https://api.lightspeedapp.com/API/Account/{Account_ID}/Sale?load_relations=["Customer.Contact"]

    But looks like it returns the RegisterID as register 1 and the employeeID as 1 as with the ShopId of 1

    Anyway to get this to return full name of and email of employee and full name of register so I can send this data to the correct Reputation account and know/attache the correct employee?

    Also I need to split this info into individual transactions and if I run a cron it will all be pulled in one big xml... Any ideas on this. See here

    https://www.useloom.com/share/80f8127979a340f48359d7f559dde776
    Post edited by scott74 on
  • Adrian SamuelAdrian Samuel Posts: 413Moderator, Lightspeed Staff moderator
    @scott74

    Q: Thanks..got token working but How do you keep it from expiring?

    A: You can't stop the access token from expiring, you'll have to periodically refresh it in your application every 30 mins or so. This is explained in our documentation here: https://developers.lightspeedhq.com/retail/authentication/refresh-token/

    If you try to make a request when the token expires receive a 401 error...you could use this to then re-authenticate your request. To make it easy for you, you could programatically create a timer for this event.


    Q: I used the Employee:all scope but wondering which permissions would be needed just to pull the register name, customer data and employee that made the sale for scopes instead of using all. This way if the correct way is sending the client a link it doesn't show as full access. Or is it best they make you a user on the account temporarily ?

    A: To limit your app access scopes, try these: employee:register, employee:customers_read.

    You can read more about access scopes here: https://developers.lightspeedhq.com/retail/authentication/scopes/

    You won't be able to set yourself on another account as a user temporarily because you'll need to be connected first to do that and it wouldn't serve any purpose for you connecting to their data via the API.

    Q: I planned on setting this up in zapier so still a little confused on what URL's you would use. We would not be have any website associated, just using to pass customer data after a sale through zapier.

    I have setup a test in postman using local host and just used my agency domain for the first URL. Just trying to get a grip on what I need to do if making this work live for a client and how to go about creating it for them if I need to login their account as a user or create these apps in my account. Please advise 

    A: Well you need a URL to authenticate the app in the first place, after that it isn't going to be useful, it's only to get the access token to connect your app to the API for their account. If you have other customers in future you'll want to have a link that people can click on and connect to in order to have the same level of access

    As long as you have an ongoing server hosted somewhere running your app you shouldn't need to worry. You'll refresh the tokens in the app programatically as well.

    To get the Employee/Register/Shop name you'll need to make a read/GET request to the relevant endpoints like so:

    https://api.lightspeed.com/API/Acccount/{{accountID}}/Employee/{{employeeID}}.json
    https://api.lightspeed.com/API/Acccount/{{accountID}}/Shop/{{shopID}}.json
    https://api.lightspeed.com/API/Account/{{accountID}}/Register/{{registerID}}.json
    
    You can read more about this here: https://developers.lightspeedhq.com/retail/endpoints/Employee/

    You'll need to split the XML/JSON data in an array containing the data from each sale.

    From the video you've shared, it looks like you've manually inserted the token for the app to work in Zapier and you're letting zapier do all the heavy lifting regarding the cron job.

    You should create a middleware between the zapier apps you want to connect with so that you can automate the process of collecting the employee, shop and register data as well as splitting the data back in chunks.

    Unless there are tools out there that I'm not aware of, you'll need to use the Zapier CLI instead of the web builder to do this.

    You can read more about this here:
    https://zapier.com/developer/documentation/v2/cli-vs-web-builder/


  • scott74scott74 Posts: 35Member
    edited December 2018
    Thanks, yes figured out that the refresh will not work through their normal front end web hooks and stuff. Thanks for the clarification.

    So to get the Register and Employee name, you have to know their ID first then do some filtering If EmployeeID is 1 "Look that up first via a get to see what it returns" then call/Pass it as John Doe

    I seem to get an error when trying to use those links. Going to need to hire some help for this one. Zapier said it looks like someone, maybe you guys started an APP for lightspeed. If this was you guys, any time frame on finishing or implementing one if it was not you?


    Post edited by scott74 on
  • Adrian SamuelAdrian Samuel Posts: 413Moderator, Lightspeed Staff moderator
    @scott74 exactly that!
  • scott74scott74 Posts: 35Member
    Thanks Adrian. I think I may have updated my response as you were replying. Mind taking a look above again...    I used this link and it responded in the Pic attached above

    https://api.lightspeed.com/API/Acccount/{Account_ID}/Employee/1.json

  • Adrian SamuelAdrian Samuel Posts: 413Moderator, Lightspeed Staff moderator
    @scott74 you wrote api.lightspeed.com when it needs to be api.lightspeedapp.com

    so the full request would be 
    https://api.lightspeedapp.com/API/Acccount/{Account_ID}/Employee/1.json

  • scott74scott74 Posts: 35Member
    edited December 2018
    Thanks, will try and pull that.


    1. Is there a way to pull sales only for todays date by entering something in this URL?
    https://api.lightspeedapp.com/API/Account/{{Account_ID}}/Sale.json?load_relations=["Customer","Customer.Contact"]

    2. That URl pulls alot of data and was reading something about your API with bucket limit. Is there a way to only make that return the Customer data, register, employee etc.. instead of everything so I'm not hitting the API has hard or does that matter?

    3. If leaving it the way it is should I have a problem with any limits if pulling the sales data each data just once for 22 store locations.
    Guessing maybe 500 sales or so roughly. Would have to ask the business. Thanks.

    Getting this going with Integromat btw. Seems to be doing the trick.

    Thanks for the help again
    Post edited by scott74 on
  • gregaricangregarican Posts: 239Member 
    edited December 2018
    I think API throttling pertains to API call counts, not necessarily the amount of data being returned in the HTTP response. So if you make a single API call to just retrieve the base sale reccord, or if you make a single API call to retrieve the base sale record and a half-dozen relations, either scenario is just a single API call against your bucket count. Although the more relations you load (esp. those with custom fields and their corresponding values) will certain slow down the response time dramatically.

    And you can definitely pull sales by a specified date range. You provide that as a URL query parameter. See https://developers.lightspeedhq.com/retail/introduction/parameters/ for details. Here is specifics in terms of querying the Sale endpoint by date --> https://community.lightspeedhq.com/en/discussion/comment/5596#Comment_5596.

    And as an FYI to @jamesratcliffe and crew, there appears to be an impacting systems issue aside from degradation in the LS Retail web client. Even my API client was getting the following HTTP response back when testing out the timeStamp scenario listed above. Just a heads-up!

    {
        "httpCode": "500",
        "httpMessage": "Internal Server Error",
        "message": "An exception occured in driver: SQLSTATE[HY000] [1040] Too many connections",
        "errorClass": "DriverException"
    }

    And also getting this...

    <html>
        <head>
            <title>524 Origin Time-out</title>
        </head>
        <body bgcolor="white">
            <center>
                <h1>524 Origin Time-out</h1>
            </center>
            <hr>
            <center>cloudflare-nginx</center>
        </body>
    </html>
  • scott74scott74 Posts: 35Member
    Thanks Greg.... I have it set to run at 9pm each night. How would this Current URL look or can it be combined to pull for the todays date which would be dynamic only? https://api.lightspeedapp.com/API/Account/{{Account_ID}}/Sale.json?load_relations=["Customer","Customer.Contact"]
  • scott74scott74 Posts: 35Member
    edited December 2018
    @scott74 you wrote api.lightspeed.com when it needs to be api.lightspeedapp.com

    so the full request would be 
    https://api.lightspeedapp.com/API/Acccount/{Account_ID}/Employee/1.json

    Hey Adrian, thanks. I am getting an error when using this with an ID of 1 

    Looks like have to add a relation I guess. This seemed to work.

    https://api.lightspeedapp.com/API/Account/{{Account_ID}}/Employee/1.json?load_relations=["Contact"]

    Got Employee and Shop URL's working but not Register to pull down the register name for some reason.

    Thanks Scott



    Post edited by scott74 on
  • Adrian SamuelAdrian Samuel Posts: 413Moderator, Lightspeed Staff moderator
    Hey @scott74 I'm not sure why you're having issues with the standard Employee and Register pull. I just tested on your account and I'm not having any issues.

    If you give full details of the request and the response, I might be able to help 
  • scott74scott74 Posts: 35Member
    Hey @scott74 I'm not sure why you're having issues with the standard Employee and Register pull. I just tested on your account and I'm not having any issues.

    If you give full details of the request and the response, I might be able to help 





    Hey Adrian.... After looking at this I think it was something with duplicating modules in integromat. I removed the link pasted it in notepad and back in the module in Integromat and it worked.



    Would you happen to be able to give me an example of a URL to only pull sales for today's date? I am going to run it on a schedule in integromat and user thier date now tag but not how the URL should be structured with the relations I have added in.

    https://api.lightspeedapp.com/API/Account/{{Account_ID}}/Sale.json?load_relations=["Customer","Customer.Contact"]
  • Adrian SamuelAdrian Samuel Posts: 413Moderator, Lightspeed Staff moderator
    edited December 2018
    Hey @scott74,

    That's great to hear! An example for today's sales for that relation would be like this:

    https://api.lightspeedapp.com/API/Account/{{accountID}}/Sale.json?timeStamp=><,2018-12-24T00:00:00+,2018-12-24T23:59:00
    This will return all sales today from UTC time midnight through to midnight. If your shop is not on UTC you want to add an offset at the end of each timestamp

    Make sure you encode your url (your software library might already do this for you)
  • scott74scott74 Posts: 35Member
    edited December 2018
    Great thanks.. Looks like I just need the & symbol to separate the time and relations correct?

    Id prefer to run this maybe every 5 minutes or so so the customers get their receipts through messenger and feedback request quicker but was not sure how that would  look with the bucket limit and would have to figure out some sort of filter to only look for new sales which I think I can probably do but would that rack up the limit restrictions? Would be about 144 request a day as the stores are open from 9am to 9pm

    Thanks for the help again

  • gregaricangregarican Posts: 239Member 
    edited December 2018
    Only 144 requests per day should be more than fine I'd imagine. Worst case, I think LS Retail API throttling allows 1 pull per second. Depending on the transactional traffic I suppose.

    Let's say you pull sales every hour. And there are 80 sales. That's only a single page of results, since you can have up to 100 records in a single page pull. Let's say you have 250 sales in that hour. Then that would be a total of 3 page pulls. But even then that operation would only take a few seconds. 

    For our one company we have on LS Retail, we required a lot of extensive data to be used for enhanced sales, customer, and inventory reporting. So I pull records from numerous endpoints into a SQL Server DB on a daily basis. Usually pulling in all of this after-hours. We only have previous business day reporting, but at least the reports render quickly and there aren't any gotchas :smiley:
  • scott74scott74 Posts: 35Member
    edited December 2018
    Cool Thanks.... Greg. Got most working. I may pull every 2 or 3 min then if that seems to be fine and try to only pull new sales that come after the previous pull.

    PS.... I have this hooked up to send data to FB Messenger if the customer is a subscriber of the bot. Was looking to Grab the Title, Description and Image of the products bought in put in a Carasoel Card why a link button going back to the product.

    Didn't see where in the API the Image of the product that the business has uploaded and description can be pulled. Did I overlook?

    Was also wondering if receipts are housed anywhere online in a URL so could link to that from messenger instead of building one out?
Sign In or Register to comment.