go-unifi

Settings

The controller settings catalogue — the generic GetSetting/SetSetting pair, the typed GetSetting<X>/UpdateSetting<X> methods, and the Setting<X>Key constants.

UniFi controller settings are keyed singletons, not list resources: each kind of setting (NTP, mDNS, management, …) has exactly one record per site. go-unifi exposes them two ways — a generic key-based pair and a typed pair per setting kind.

All settings methods take a context.Context and a site name string ("default").

For each setting kind X there is a matching struct Setting<X> and a method pair:

GetSetting<X>(ctx, site)            (*Setting<X>, error)
UpdateSetting<X>(ctx, site, *Setting<X>) (*Setting<X>, error)

The typical edit is read-modify-write — fetch, change a field, write back:

settings.go
package main

import (
	"context"
	"log"

	"github.com/filipowm/go-unifi/v2/unifi"
)

func main() {
	ctx := context.Background()
	c, err := unifi.NewClient(&unifi.ClientConfig{URL: "https://unifi.example.com", APIKey: "your-api-key"})
	if err != nil {
		log.Fatal(err)
	}

	ntp, err := c.GetSettingNtp(ctx, "default")
	if err != nil {
		log.Fatalf("get ntp setting: %v", err)
	}

	// ...mutate ntp fields here...

	if _, err := c.UpdateSettingNtp(ctx, "default", ntp); err != nil {
		log.Fatalf("update ntp setting: %v", err)
	}
}

The verbs are asymmetric: reads are GetSetting<X>, writes are UpdateSetting<X> — but the generic write (below) is SetSetting, not UpdateSetting.

Generic accessors

When you want to work by key (e.g. a setting kind without a typed wrapper, or dynamic code), use the generic pair:

GetSetting(ctx, site, key)            (*Setting, any, error)
SetSetting(ctx, site, key, reqBody any) (any, error)

GetSetting returns the bare Setting envelope (ID, SiteID, Key) plus the decoded fields as an any — which is a *Setting<X> pointer you type-assert. Pass the matching Setting<X>Key constant:

generic_setting.go
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/filipowm/go-unifi/v2/unifi"
)

func main() {
	ctx := context.Background()
	c, err := unifi.NewClient(&unifi.ClientConfig{URL: "https://unifi.example.com", APIKey: "your-api-key"})
	if err != nil {
		log.Fatal(err)
	}

	setting, fields, err := c.GetSetting(ctx, "default", unifi.SettingMgmtKey)
	if err != nil {
		log.Fatal(err)
	}
	mgmt, ok := fields.(*unifi.SettingMgmt)
	if !ok {
		log.Fatalf("unexpected fields type for key %q", setting.Key)
	}
	fmt.Println(mgmt.SiteID)
}

Both pairs decode the same way: the key resolves to a generated factory that returns a fresh *Setting<X>. An unknown key yields an unexpected key error; a key absent from the controller's response yields ErrNotFound.

Catalogue

Every kind below has a Setting<X> struct, a Setting<X>Key constant, and a typed GetSetting<X> / UpdateSetting<X> pair. Field-level detail lives on pkg.go.dev.

X (type / method suffix)Setting<X>Key valueCovers
AutoSpeedtestauto_speedtestScheduled automatic speed tests.
BaresipbaresipVoIP (baresip) integration.
BroadcastbroadcastBroadcast / PA audio.
ConnectivityconnectivityUplink connectivity monitoring.
CountrycountrySite country / regulatory domain.
DashboarddashboardDashboard preferences.
DohdohDNS-over-HTTPS.
DpidpiDeep packet inspection.
ElementAdoptelement_adoptUniFi Element adoption.
EtherLightingether_lightingSwitch port LED / ether-lighting.
EvaluationScoreevaluation_scoreNetwork experience score.
GlobalApglobal_apGlobal access-point defaults.
GlobalNatglobal_natGlobal NAT behaviour.
GlobalSwitchglobal_switchGlobal switch defaults.
GuestAccessguest_accessGuest portal / hotspot access.
IpsipsIntrusion prevention / detection.
LcmlcmDevice LCD / LCM screen.
LocalelocaleSite locale / timezone.
MagicSiteToSiteVpnmagic_site_to_site_vpnAuto site-to-site VPN.
MdnsmdnsMulticast DNS (Bonjour) forwarding.
MgmtmgmtDevice management (SSH, etc.).
NetflownetflowNetFlow export.
NetworkOptimizationnetwork_optimizationAutomatic network optimization.
NtpntpNTP servers.
PortaportaHotspot portal customization.
RadioAiradio_aiAI RF / radio optimization.
RadiusradiusBuilt-in RADIUS server.
RoamingAssistantroaming_assistantClient roaming assistance.
RsyslogdrsyslogdRemote syslog.
SnmpsnmpSNMP agent.
SslInspectionssl_inspectionSSL inspection.
SuperCloudaccesssuper_cloudaccessController-wide remote (cloud) access.
SuperEventssuper_eventsController-wide event retention.
SuperFwupdatesuper_fwupdateController-wide firmware-update policy.
SuperIdentitysuper_identityController identity / name.
SuperMailsuper_mailController-wide mail.
SuperMgmtsuper_mgmtController-wide management.
SuperSdnsuper_sdnController-wide SDN / cloud integration.
SuperSmtpsuper_smtpController-wide SMTP server.
TeleportteleportTeleport VPN.
TrafficFlowtraffic_flowTraffic-flow analytics.
UsgusgGateway (USG / UDM) settings.
UswuswSwitch (USW) settings.

The Super* kinds are controller-wide rather than per-site, but you still read and write them with the same site-scoped methods (use "default").

See also

On this page