API: Can't assign tenant when creating IP address #6383

Closed
opened 2025-12-29 19:40:04 +01:00 by adam · 2 comments
Owner

Originally created by @Faabvk on GitHub (Apr 20, 2022).

NetBox version

Discovered on v3.2.0, persists on v3.2.1

Python version

3.10

Steps to Reproduce

  1. Send a POST request to /api/ipam/ip-addresses/, specifying the address and status as string, and tenant ID as integer, as described by the API docs. Example below:
import requests
API_KEY = '<your api token>'
# Manually converting to integer just to 100% verify it can't go wrong.
tenant = int(1)
print(type(int)) # <class 'int'>

url = "https://netbox.example.com/api/ipam/ip-addresses/"

payload={ 
  'address': '192.168.1.1/24',
  'tenant': tenant,
  'status': 'active',
}

headers = {
  'Authorization': 'Token ' + API_KEY
}

print(payload) # {'address': '192.168.1.1/24', 'tenant': 1, 'status': 'active'}
response = requests.request("POST", url, headers=headers, data=payload)

Expected Behavior

A new IP address should be added in Netbox, with a Tenant attached to it.

Observed Behavior

The new IP address is made, and the API correctly fills other fields like description and dns_name, but Tenant is null.
Here is the payload I sent:
{'address': '192.168.1.1/24', 'tenant': 18, 'status': 'active', 'dns_name': 'test', 'description': 'test'}
And the response I received.

{
   "id":540,
   "url":"https://netbox.example.com/api/ipam/ip-addresses/540/",
   "display":"192.168.1.1/24",
   "family":{
      "value":4,
      "label":"IPv4"
   },
   "address":"192.168.1.1/24",
   "vrf":null,
   "tenant":null,
   "status":{
      "value":"active",
      "label":"Active"
   },
   "role":null,
   "assigned_object_type":null,
   "assigned_object_id":null,
   "assigned_object":null,
   "nat_inside":null,
   "nat_outside":null,
   "dns_name":"test",
   "description":"test",
   "tags":[
      
   ],
   "custom_fields":{
      
   },
   "created":"2022-04-20T15:19:46.847398Z",
   "last_updated":"2022-04-20T15:19:46.847410Z"
}
Originally created by @Faabvk on GitHub (Apr 20, 2022). ### NetBox version Discovered on v3.2.0, persists on v3.2.1 ### Python version 3.10 ### Steps to Reproduce 1. Send a POST request to `/api/ipam/ip-addresses/`, specifying the address and status as string, and tenant ID as integer, as described by the API docs. Example below: ```Python import requests API_KEY = '<your api token>' # Manually converting to integer just to 100% verify it can't go wrong. tenant = int(1) print(type(int)) # <class 'int'> url = "https://netbox.example.com/api/ipam/ip-addresses/" payload={ 'address': '192.168.1.1/24', 'tenant': tenant, 'status': 'active', } headers = { 'Authorization': 'Token ' + API_KEY } print(payload) # {'address': '192.168.1.1/24', 'tenant': 1, 'status': 'active'} response = requests.request("POST", url, headers=headers, data=payload) ``` ### Expected Behavior A new IP address should be added in Netbox, with a Tenant attached to it. ### Observed Behavior The new IP address is made, and the API correctly fills other fields like description and dns_name, but Tenant is null. Here is the payload I sent: `{'address': '192.168.1.1/24', 'tenant': 18, 'status': 'active', 'dns_name': 'test', 'description': 'test'}` And the response I received. ```JSON { "id":540, "url":"https://netbox.example.com/api/ipam/ip-addresses/540/", "display":"192.168.1.1/24", "family":{ "value":4, "label":"IPv4" }, "address":"192.168.1.1/24", "vrf":null, "tenant":null, "status":{ "value":"active", "label":"Active" }, "role":null, "assigned_object_type":null, "assigned_object_id":null, "assigned_object":null, "nat_inside":null, "nat_outside":null, "dns_name":"test", "description":"test", "tags":[ ], "custom_fields":{ }, "created":"2022-04-20T15:19:46.847398Z", "last_updated":"2022-04-20T15:19:46.847410Z" } ```
adam added the type: bug label 2025-12-29 19:40:04 +01:00
adam closed this issue 2025-12-29 19:40:04 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 20, 2022):

I'm not able to reproduce this on v3.2.1. The following query succeeds in creating the IP address with the assigned tenant as expected:

curl -X POST \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
http://netbox:8000/api/ipam/ip-addresses/ \
--data '{"address": "192.168.1.1/24", "status": "active", "tenant": 7}'

It looks like the request your sending lacks the proper content type, which is likely the cause of your issue. Try adding a Content-Type: application/json header.

@jeremystretch commented on GitHub (Apr 20, 2022): I'm not able to reproduce this on v3.2.1. The following query succeeds in creating the IP address with the assigned tenant as expected: ``` curl -X POST \ -H "Authorization: Token $TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ http://netbox:8000/api/ipam/ip-addresses/ \ --data '{"address": "192.168.1.1/24", "status": "active", "tenant": 7}' ``` It looks like the request your sending lacks the proper content type, which is likely the cause of your issue. Try adding a `Content-Type: application/json` header.
Author
Owner

@Faabvk commented on GitHub (Apr 21, 2022):

Confirmed! Thanks Jeremy, for the swift response and solution!

@Faabvk commented on GitHub (Apr 21, 2022): Confirmed! Thanks Jeremy, for the swift response and solution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6383