Merge pull request #500 from dsvetlov/feature/netbox-4.5-v2-token-support

feat: add support for NetBox 4.5+ v2 API tokens (Bearer auth)
This commit is contained in:
Ricardo
2026-04-07 16:12:43 +02:00
committed by GitHub
4 changed files with 9 additions and 3 deletions
+2
View File
@@ -79,6 +79,8 @@ In order to updated data in NetBox you need a NetBox API token.
* auth
* secrets
* users
* Both v1 (legacy) and v2 tokens (NetBox 4.5+, `nbt_` prefix) are supported.
The correct authorization header (`Token` or `Bearer`) is detected automatically.
A short description can be found [here](https://docs.netbox.dev/en/stable/integrations/rest-api/#authentication)
+2 -1
View File
@@ -26,7 +26,8 @@ class NetBoxConfig(ConfigBase):
ConfigOption("api_token",
str,
description="""Requires an NetBox API token with full permissions on all objects except
'auth', 'secrets' and 'users'
'auth', 'secrets' and 'users'.
Both v1 (legacy) and v2 (NetBox 4.5+, nbt_ prefix) tokens are supported.
""",
config_example="XYZ",
mandatory=True,
+3 -1
View File
@@ -152,8 +152,10 @@ class NetBoxHandler:
requests.Session: session handler of new NetBox session
"""
token = self.settings.api_token
keyword = "Bearer" if token.startswith("nbt_") else "Token"
header = {
"Authorization": f"Token {self.settings.api_token}",
"Authorization": f"{keyword} {token}",
"User-Agent": f"netbox-sync/{__version__}",
"Content-Type": "application/json"
}
+2 -1
View File
@@ -44,7 +44,8 @@
[netbox]
; Requires an NetBox API token with full permissions on all objects except 'auth',
; 'secrets' and 'users'
; 'secrets' and 'users'. Both v1 (legacy) and v2 (NetBox 4.5+, nbt_ prefix) tokens are
; supported.
api_token = XYZ
; Requires a hostname or IP which points to your NetBox instance