File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,6 +79,8 @@ In order to updated data in NetBox you need a NetBox API token.
7979 * auth
8080 * secrets
8181 * users
82+ * Both v1 (legacy) and v2 tokens (NetBox 4.5+, ` nbt_ ` prefix) are supported.
83+ The correct authorization header (` Token ` or ` Bearer ` ) is detected automatically.
8284
8385A short description can be found [ here] ( https://docs.netbox.dev/en/stable/integrations/rest-api/#authentication )
8486
Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ def __init__(self):
2626 ConfigOption ("api_token" ,
2727 str ,
2828 description = """Requires an NetBox API token with full permissions on all objects except
29- 'auth', 'secrets' and 'users'
29+ 'auth', 'secrets' and 'users'.
30+ Both v1 (legacy) and v2 (NetBox 4.5+, nbt_ prefix) tokens are supported.
3031 """ ,
3132 config_example = "XYZ" ,
3233 mandatory = True ,
Original file line number Diff line number Diff line change @@ -152,8 +152,10 @@ def create_session(self) -> requests.Session:
152152 requests.Session: session handler of new NetBox session
153153 """
154154
155+ token = self .settings .api_token
156+ keyword = "Bearer" if token .startswith ("nbt_" ) else "Token"
155157 header = {
156- "Authorization" : f"Token { self . settings . api_token } " ,
158+ "Authorization" : f"{ keyword } { token } " ,
157159 "User-Agent" : f"netbox-sync/{ __version__ } " ,
158160 "Content-Type" : "application/json"
159161 }
Original file line number Diff line number Diff line change 4444[netbox]
4545
4646; Requires an NetBox API token with full permissions on all objects except 'auth',
47- ; 'secrets' and 'users'
47+ ; 'secrets' and 'users'. Both v1 (legacy) and v2 (NetBox 4.5+, nbt_ prefix) tokens are
48+ ; supported.
4849api_token = XYZ
4950
5051; Requires a hostname or IP which points to your NetBox instance
You can’t perform that action at this time.
0 commit comments