Module: LoyverseApi::Endpoints::Items

Included in:
Client
Defined in:
lib/loyverse_api/endpoints/items.rb

Instance Method Summary collapse

Instance Method Details

#create_item(item_name:, category_id: nil, variants: [], track_stock: false, sold_by_weight: false, is_composite: false) ⇒ Hash

Create a new item

Parameters:

  • item_name (String) —

    Name of the item

  • category_id (String) (defaults to: nil) —

    UUID of the category (optional)

  • variants (Array<Hash>) (defaults to: []) —

    Array of variant hashes

  • track_stock (Boolean) (defaults to: false) —

    Whether to track inventory

  • sold_by_weight (Boolean) (defaults to: false) —

    Whether item is sold by weight

  • is_composite (Boolean) (defaults to: false) —

    Whether item is composite

Returns:

  • (Hash) —

    Created item details



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/loyverse_api/endpoints/items.rb', line 36

def create_item(item_name:, category_id: nil, variants: [], track_stock: false, sold_by_weight: false, is_composite: false)
  body = {
    item_name: item_name,
    track_stock: track_stock,
    sold_by_weight: sold_by_weight,
    is_composite: is_composite
  }
  body[:category_id] = category_id if category_id
  body[:variants] = variants unless variants.empty?

  post("items", body: body)
end

#delete_item(item_id) ⇒ Hash

Delete an item

Parameters:

  • item_id (String) —

    UUID of the item

Returns:

  • (Hash) —

    Response



70
71
72
# File 'lib/loyverse_api/endpoints/items.rb', line 70

def delete_item(item_id)
  delete("items/#{item_id}")
end

#get_item(item_id) ⇒ Hash

Get a specific item by ID

Parameters:

  • item_id (String) —

    UUID of the item

Returns:

  • (Hash) —

    Item details



7
8
9
# File 'lib/loyverse_api/endpoints/items.rb', line 7

def get_item(item_id)
  get("items/#{item_id}")
end

#list_items(limit: 250, cursor: nil, updated_at_min: nil, updated_at_max: nil) ⇒ Hash

List items

Parameters:

  • limit (Integer) (defaults to: 250) —

    Maximum number of results per page (default: 250)

  • cursor (String) (defaults to: nil) —

    Pagination cursor for next page

  • updated_at_min (String, Time) (defaults to: nil) —

    Filter by minimum update time (ISO 8601)

  • updated_at_max (String, Time) (defaults to: nil) —

    Filter by maximum update time (ISO 8601)

Returns:

  • (Hash) —

    Response with items array



17
18
19
20
21
22
23
24
25
26
# File 'lib/loyverse_api/endpoints/items.rb', line 17

def list_items(limit: 250, cursor: nil, updated_at_min: nil, updated_at_max: nil)
  params = {
    limit: limit,
    cursor: cursor,
    updated_at_min: format_time(updated_at_min),
    updated_at_max: format_time(updated_at_max)
  }.compact

  get("items", params: params)
end

#update_item(item_id, item_name: nil, category_id: nil, variants: nil, track_stock: nil) ⇒ Hash

Update an existing item

Parameters:

  • item_id (String) —

    UUID of the item

  • item_name (String) (defaults to: nil) —

    Name of the item (optional)

  • category_id (String) (defaults to: nil) —

    UUID of the category (optional)

  • variants (Array<Hash>) (defaults to: nil) —

    Array of variant hashes (optional)

  • track_stock (Boolean) (defaults to: nil) —

    Whether to track inventory (optional)

Returns:

  • (Hash) —

    Updated item details



56
57
58
59
60
61
62
63
64
65
# File 'lib/loyverse_api/endpoints/items.rb', line 56

def update_item(item_id, item_name: nil, category_id: nil, variants: nil, track_stock: nil)
  body = {
    item_name: item_name,
    category_id: category_id,
    variants: variants,
    track_stock: track_stock
  }.compact

  put("items/#{item_id}", body: body)
end