Lightspeed POS

An unofficial gem for interacting with Lightspeed's Point of Sale API, (documentation).

Not all endpoints are implemented yet, but you can help by submitting pull requests!

Getting Started

First, intialize a new client:

client = Lightspeed::Client.new(oauth_token: "YOUR_ACCESS_TOKEN_HERE")

Next, make a request for your accounts:

accounts = client.accounts.all

Pick the account you want to use, and then start using it:

 = accounts.first
.items.first

Resources

resources share a common API. Resources that are currently supported by this library are:

  • Accounts
  • Categories
  • Employees
  • Items
  • Item Matrices
  • Item Attribute Sets
  • Images
  • Inventories
  • Orders
  • Sales
  • Shops
  • Special Orders
  • Vendors

To work with account resources, you first need to fetch an account. The examples below are for items, but will also work with other types listed above.

List

You can fetch a list of items with this:

.items.all

You can pass query parameters to this by using the params keyword:

.items.all(params: { itemMatrixID: 0 })

You can enumerate over a group of 100 resources at a time (the max in a single request) using each_page

.items.each_page! do |items|
  # ItemImporter.import(items)
end

Or enumerate over each resource using #each (this still only does a request for each 100 items)

.items.each do |item|
  # ItemImporter.import(item)
end

Show

You can fetch a particular item by its ID by doing this:

.items.find(1)

If item with id of 1 is not there, this will raise Lightspeed::Error::NotFound

You can fetch the first item using first

.items.first

Create

You can create a particular item by calling create:

.items.create(description: "Onesie")

Update

You can update a particular item by calling update, passing that item's ID and providing a list of attributes to update:

.items.update(1, description: "Onesie")
# OR
.items.find(1)
item.update(description: "Onesie")

Destroy

You can destroy a particular item by calling destroy and passing that item's ID:

.images.destroy(1)
# OR
.images.find(1)
item.destroy

For the Item resource, destroy is aliased to archive:

Rate Limiting

This gem respects the X-LS-API-Bucket-Level header by pausing before a request that would otherwise overrun the API rate limit. It calls Kernel.sleep with the minimum number of seconds needed to avoid hitting the limit, which suspends the current thread during that time. If you need to make API calls across multiple Lightspeed accounts using this gem, its recommended to make requests against each account in a separate thread.