Netbox REST Task¤
task api name:
rest
Sends a direct HTTP request to the configured NetBox REST API. Use this task when a dedicated NetBox worker task does not exist for the endpoint you need.
Inputs¤
| Parameter | Required | Description |
|---|---|---|
api |
Yes | NetBox API path under /api, for example dcim/devices |
method |
No | HTTP method to use, default get |
instance |
No | NetBox instance name to target |
**kwargs |
No | Additional request arguments passed to requests, such as params, json, or data |
Output¤
Returns the decoded JSON response from NetBox when possible. If the response is not JSON, the task returns response text or the HTTP status code.
Notes / Gotchas¤
apiis joined under the configured NetBox URL as/api/<api>/.- Request headers, token, SSL verification, and default timeout are set by the worker.
- On HTTP errors, the task returns the response status code in
result. - The current NFCLI command model does not expose
rest, so use the Python API or other task surfaces.
Examples¤
Context manager:
from norfab.core.nfapi import NorFab
with NorFab(inventory="./inventory.yaml") as nf:
client = nf.make_client()
result = client.run_job(
"netbox",
"rest",
workers="any",
kwargs={
"api": "dcim/devices",
"method": "get",
"params": {"q": "ceos-leaf"},
},
)
Direct lifecycle:
from norfab.core.nfapi import NorFab
nf = NorFab(inventory="./inventory.yaml")
try:
nf.start()
client = nf.make_client()
result = client.run_job(
"netbox",
"rest",
workers="any",
kwargs={
"api": "extras/tags",
"method": "post",
"json": {
"name": "automation-managed",
"slug": "automation-managed",
},
},
)
finally:
nf.destroy()
Python API Reference¤
Sends a request to the Netbox REST API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
str
|
The Netbox instance name to get parameters for. |
None
|
method
|
str
|
The HTTP method to use for the request (e.g., 'get', 'post'). Defaults to "get". |
'get'
|
api
|
str
|
The API endpoint to send the request to. Defaults to "". |
''
|
**kwargs
|
Any
|
Additional arguments to pass to the request (e.g., params, data, json). |
{}
|
Returns:
| Type | Description |
|---|---|
Result
|
Union[dict, list]: The JSON response from the API, parsed into a dictionary or list. |
Raises:
| Type | Description |
|---|---|
HTTPError
|
If the HTTP request returned an unsuccessful status code. |
Source code in norfab\workers\netbox_worker\netbox_worker.py
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 | |