Request failed with code 400 Bad Request when trying to use the NetBox API to create a cable connection #148894
Replies: 2 comments
-
Hi Johan, The error you’re encountering suggests that the NetBox API requires both terminations (termination_a and termination_b) to be properly defined when creating a cable. Based on the code you’ve shared, the issue may be with the naming of the parameters or the exact structure of the create() function. In NetBox v4.x, the parameters for creating a cable have slightly changed. The terminations need to be specified as a list of dictionaries. Here’s an updated version of your code that should work: Updated Code: Initialize the NetBox APInb = pynetbox.api('http://10.129.201.216/', token='all long code') Define the terminationstermination_a = { try: Best regards |
Beta Was this translation helpful? Give feedback.
-
Hi, |
Beta Was this translation helpful? Give feedback.
-
Body
Hi all,
I'm unable to create a cable between two interfaces using the NetBox API. Receiving the error: pynetbox.core.query.RequestError: The request failed with code 400 Bad Request: {'all': ['Must define A and B terminations when creating a new cable.']}.
Details:
Interface A:
Device: evs-edge-1
Ethernet: Ethernet 11
ID: 1326
Interface B:
Device: evs-spine-1
Ethernet: Ethernet 1
ID: 1350
The ID's have been verified and are accessible thru the web interface.
Code:
Python
import pynetbox
Initialize the NetBox API
nb = pynetbox.api('http://10.129.201.216/', token='all long code')
Define the IDs and types for the terminations
termination_a_type = "dcim.interface"
termination_a_id = 1326 # Ethernet 11 on evs-edge-1
termination_b_type = "dcim.interface"
termination_b_id = 1350 # Ethernet 1 on evs-spine-1
try:
# Create the new cable
new_cable = nb.dcim.cables.create(
termination_a_type=termination_a_type,
termination_a_id=termination_a_id,
termination_b_type=termination_b_type,
termination_b_id=termination_b_id
)
print(f"Cable created successfully: {new_cable}")
except pynetbox.RequestError as e:
# Handle the request error
print(f"The request failed with code {e.response.status_code}: {e.error}")
NetBox release | NetBox Community v4.1.2 (2024-09-26)
Python version 3.12.6
Django version 5.0.9
Any help is welcome.
Johan
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions