create mac address object via api #11486

Closed
opened 2025-12-29 21:45:56 +01:00 by adam · 1 comment
Owner

Originally created by @IliasTsarouchas on GitHub (Aug 14, 2025).

Deployment Type

Self-hosted

NetBox Version

v4.3.4

Python Version

3.10

Steps to Reproduce

While creating api request by python script:

(Create Mac Address)

headers = {
"Authorization": f"Token {NETBOX_API_TOKEN}",
"accept": "application/json",
"Content-Type": "application/json"
}

params = {
"mac_address": mac_address,
"display": mac_address,
"assigned_object_type":"dcim.interface",
"assigned_object_id":assigned_object_id,
"description":mac_address,
"comments":mac_address,
"tags":[3],
}
try:
# Query physical interfaces
response_mac = requests.post(f"{NETBOX_API_URL}dcim/mac-addresses/", headers=headers, params=params, verify=False)
response_mac.raise_for_status() # Raise an exception for non-200 status codes
if response_mac.status_code == 201:
#response_mac.raise_for_status() # Raise an exception for non-200 status codes
macaddress = response_mac.json().get("results", [])
print(macaddress)
# Display results
if macaddress:
for result in macaddress:
print(f"MAC Address exits: {result['mac_address']}")
macID = result['id']
return macID
print(f"MAC Address: {mac_address} - Not found in NetBox")
return "NotFound"
except requests.exceptions.RequestException as e:
print(f"Error querying NetBox API: {e}")
# for ex in e:
# print(ex)
return 0

We tried with PUT and POST method with same json parameters. The request is successfull over the webinterface (https://netbox/api/schema/swagger-ui)

Expected Behavior

Mac Address is created unter dcim/mac-addresses

Observed Behavior

Error querying NetBox API: 400 Client Error: Bad Request for url: https://ip.add.re.ss/api/dcim/mac-addresses/?mac_address=FF%3AFF%3AFF%3A99%3A99%3A11&display=FF%3AFF%3AFF%3A99%3A99%3A11&assigned_object_type=dcim.interface&assigned_object_id=123&description=FF%3AFF%3AFF%3A99%3A99%3A11&comments=FF%3AFF%3AFF%3A99%3A99%3A11&tags=3

Originally created by @IliasTsarouchas on GitHub (Aug 14, 2025). ### Deployment Type Self-hosted ### NetBox Version v4.3.4 ### Python Version 3.10 ### Steps to Reproduce While creating api request by python script: (Create Mac Address) headers = { "Authorization": f"Token {NETBOX_API_TOKEN}", "accept": "application/json", "Content-Type": "application/json" } params = { "mac_address": mac_address, "display": mac_address, "assigned_object_type":"dcim.interface", "assigned_object_id":assigned_object_id, "description":mac_address, "comments":mac_address, "tags":[3], } try: # Query physical interfaces response_mac = requests.post(f"{NETBOX_API_URL}dcim/mac-addresses/", headers=headers, params=params, verify=False) response_mac.raise_for_status() # Raise an exception for non-200 status codes if response_mac.status_code == 201: #response_mac.raise_for_status() # Raise an exception for non-200 status codes macaddress = response_mac.json().get("results", []) print(macaddress) # Display results if macaddress: for result in macaddress: print(f"MAC Address exits: {result['mac_address']}") macID = result['id'] return macID print(f"MAC Address: {mac_address} - Not found in NetBox") return "NotFound" except requests.exceptions.RequestException as e: print(f"Error querying NetBox API: {e}") # for ex in e: # print(ex) return 0 We tried with PUT and POST method with same json parameters. The request is successfull over the webinterface (https://netbox/api/schema/swagger-ui) ### Expected Behavior Mac Address is created unter dcim/mac-addresses ### Observed Behavior Error querying NetBox API: 400 Client Error: Bad Request for url: https://ip.add.re.ss/api/dcim/mac-addresses/?mac_address=FF%3AFF%3AFF%3A99%3A99%3A11&display=FF%3AFF%3AFF%3A99%3A99%3A11&assigned_object_type=dcim.interface&assigned_object_id=123&description=FF%3AFF%3AFF%3A99%3A99%3A11&comments=FF%3AFF%3AFF%3A99%3A99%3A11&tags=3
adam added the netbox label 2025-12-29 21:45:56 +01:00
adam closed this issue 2025-12-29 21:45:56 +01:00
Author
Owner

@bctiemann commented on GitHub (Aug 15, 2025):

The 400 response will report the validation errors from the serializer. If you're not able to determine the issue from the response payload, please open this as a Discussion as this is likely not a bug.

@bctiemann commented on GitHub (Aug 15, 2025): The 400 response will report the validation errors from the serializer. If you're not able to determine the issue from the response payload, please open this as a Discussion as this is likely not a bug.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11486