-
Notifications
You must be signed in to change notification settings - Fork 4
Upload file by pynetbox API
Jan Krupa edited this page Jul 17, 2024
·
1 revision
import ipdb # debugger
from pynetbox import api
# Initialize the NetBox API connection
netbox = api(url="NETBOX_URL", token="NETBOX_TOKEN")
# Update session headers with the authorization token
netbox.http_session.headers.update({"Authorization": f"Token {netbox.token}"})
# Open the file to be uploaded
with open("README.md", "rb") as f:
ipdb.set_trace() # Start debugger here
# Post request to upload the file
response = netbox.http_session.post(
f"{netbox.base_url}/plugins/netbox-attachments/netbox-attachments/",
data={
"object_type": "dcim.device",
"object_id": 710,
"name": "django",
"comments": "comment",
},
files={"file": ("django", f)},
)
ipdb.set_trace() # Debugger breakpoint after the request