Skip to content

Feature request: Create 'hotspot' vouchers per site #13

@Joeym0180

Description

@Joeym0180

Hi,

Just missed the possibility to create vouchers per site.

Below is the code i used to create vouchers via Powershell. (hope you add it in some way to your module)

param (
       [string]$visitor
)
$uri  = 'https://unificontroller.domain.local:8443'
$site = 'xxxxxxxx' #siteid of  the customer site
$vouchernote = "vouchernote-$visitor"

$UnifiUsername = ""
$UnifiPassword = ""

# Enables TLS1.2 -- this is a universal method that works for any dot net version
[Net.ServicePointManager]::SecurityProtocol = [Enum]::ToObject([Net.SecurityProtocolType], 3072)

# Ignore self-signed certificates 
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }


# login call
$param = @{
    URI         = $uri + '/api/login'
    Method      = 'post'
    Body        = @{
        username = $UnifiUsername
        password = $UnifiPassword
    } | ConvertTo-Json -Compress
    contenttype = "application/json; charset=utf-8"
}

$logincall = Invoke-RestMethod @param -SessionVariable session
if ($logincall.meta.rc -eq 'ok') {
    write-host 'Authenticated successfully' -ForegroundColor Green
}
# end of login call

# voucher call
$param = @{
    URI         = $uri + "/api/s/$site/cmd/hotspot"
    Method      = 'post'
    Body        = @{
        cmd    = 'create-voucher'
        expire = 600              # voucher expire time in minutes
        n      = 1                # count of vouchers you want to generate
        note   = $vouchernote     # description of voucher visible in the hotspot manager
    } | ConvertTo-Json -Compress
    contenttype = "application/json; charset=utf-8"
}
$vouchercreatecall = Invoke-RestMethod @param -WebSession $session

if ($vouchercreatecall.meta.rc -eq 'ok') {
    write-host 'Created Voucher successfully' -ForegroundColor Green
    $param = @{
        URI         = $uri + "/api/s/$site/stat/voucher"
        Method      = 'post'
        Body        = @{
            create_time = $vouchercreatecall.data.create_time
        } | ConvertTo-Json -Compress
        contenttype = "application/json; charset=utf-8"
    }
    $vouchergetcall = Invoke-RestMethod @param -WebSession $session
    if ($vouchergetcall.meta.rc -eq 'ok') {
        write-host 'Received Voucher successfully' -ForegroundColor Green
         # returnvalue is based on 1 voucher. 
        $voucher = [pscustomobject]@{
            voucher = ($vouchergetcall.data.code[0..4] + '-' + $vouchergetcall.data.code[5..9]) -join ''
            #voucher = $vouchergetcall.data.code
            note    = $vouchergetcall.data.note
        }
    }
}
return $voucher

#return "$($voucher.voucher)"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions