Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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)

Expand Down
3 changes: 2 additions & 1 deletion module/netbox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def __init__(self):
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,
Expand Down
4 changes: 3 additions & 1 deletion module/netbox/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ def create_session(self) -> requests.Session:
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"
}
Expand Down
3 changes: 2 additions & 1 deletion settings-example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down