UniFi Network API — hotspot voucher management.
Create, list, and delete guest access vouchers.
Voucher fields
id,name,codecreatedAt,activatedAt,expiresAt,expiredauthorizedGuestLimit,authorizedGuestCounttimeLimitMinutes,dataUsageLimitMBytesrxRateLimitKbps,txRateLimitKbps
Summary
Functions
Creates one or more vouchers (1-1000 at a time).
Deletes a specific voucher.
Deletes all vouchers on a site.
Gets a specific voucher by ID.
Lists all hotspot vouchers on a site.
Returns a lazy stream that auto-paginates through all vouchers.
Functions
@spec create_vouchers(Req.Request.t(), String.t(), map()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Creates one or more vouchers (1-1000 at a time).
Body fields
count— number of vouchers to create (1-1000, required)name— voucher labeltimeLimitMinutes— session durationauthorizedGuestLimit— max guests per voucherdataUsageLimitMBytes— data caprxRateLimitKbps— download speed limittxRateLimitKbps— upload speed limit
Examples
{:ok, vouchers} = UnifiApi.Network.Hotspot.create_vouchers(client, site_id, %{
count: 10,
name: "Event Pass",
timeLimitMinutes: 1440,
authorizedGuestLimit: 1,
dataUsageLimitMBytes: 500,
rxRateLimitKbps: 5000,
txRateLimitKbps: 1000
})
@spec delete_voucher(Req.Request.t(), String.t(), String.t()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Deletes a specific voucher.
Examples
{:ok, _} = UnifiApi.Network.Hotspot.delete_voucher(client, site_id, voucher_id)
@spec delete_vouchers(Req.Request.t(), String.t()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Deletes all vouchers on a site.
Examples
{:ok, _} = UnifiApi.Network.Hotspot.delete_vouchers(client, site_id)
@spec get_voucher(Req.Request.t(), String.t(), String.t()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Gets a specific voucher by ID.
Examples
{:ok, voucher} = UnifiApi.Network.Hotspot.get_voucher(client, site_id, voucher_id)
voucher["code"] # => "12345-67890"
voucher["expired"] # => false
@spec list_vouchers(Req.Request.t(), String.t(), keyword()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Lists all hotspot vouchers on a site.
Options
Supports pagination: :offset, :limit, :filter.
Examples
{:ok, vouchers} = UnifiApi.Network.Hotspot.list_vouchers(client, site_id)
@spec stream_vouchers(Req.Request.t(), String.t(), keyword()) :: Enumerable.t()
Returns a lazy stream that auto-paginates through all vouchers.
Error contract
A mid-stream error does not raise by default: the stream halts and
yields {:error, %UnifiApi.StreamError{}, last_offset} as its final
element, so the enumerable is heterogeneous. Match the tail:
case Enum.to_list(stream) do
items when is_list(items) ->
case List.last(items) do
{:error, error, cursor} -> {:error, error, cursor}
_ -> {:ok, items}
end
endPass raise_errors: true to raise UnifiApi.StreamError instead.
Options
:max_pages— halt after this many successful pages (default: unbounded).:max_items— halt once this many items have been yielded (default: unbounded).:raise_errors— raiseUnifiApi.StreamErroron error instead of yielding the error tuple (default:false).
Examples
# Get all active voucher codes
UnifiApi.Network.Hotspot.stream_vouchers(client, site_id, raise_errors: true)
|> Stream.reject(& &1["expired"])
|> Enum.map(& &1["code"])