Unable to set 'assigned_object_id' when creating IP addresses via the API #4070

Closed
opened 2025-12-29 18:32:57 +01:00 by adam · 3 comments
Owner

Originally created by @fantasmita on GitHub (Sep 5, 2020).

Environment

  • Python version: 3.6.5
  • NetBox version: 2.9.3

Steps to Reproduce

  1. Get the ID of a existing interface object (74005 in my example here)
  2. Create an IP address and set that ID value to the assigned_object_id via
curl -X POST -H "Authorization: Token $TOKEN" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" https://$NETBOX/api/ipam/ip-addresses/ --data '{"address": "1.2.3.4/32", "assigned_object_id": 74005}'

In the returned JSON, you will see the assigned_object_id set correctly like this:

{                                                                                                                                                                                             
    "id": 45731,                                                                                                                                                                              
    "url": "https://$NETBOX/api/ipam/ip-addresses/45731/",                                                                                                              
    "family": {                                                                                                                                                                               
        "value": 4,                                                                                                                                                                           
        "label": "IPv4"                                                                                                                                                                       
    },                                                                                                                                                                                        
    "address": "1.2.3.4/32",                                                                                                                                                                  
    "vrf": null,                                                                                                                                                                              
    "tenant": null,                                                                                                                                                                           
    "status": {                                                                                                                                                                               
        "value": "active",                                                                                                                                                                    
        "label": "Active"                                                                                                                                                                     
    },                                                                                                                                                                                        
    "role": null,                                                                                                                                                                             
    "assigned_object_type": null,                                                                                                                                                             
    "assigned_object_id": 74005,                                                                                                                                                              
    "assigned_object": null,                                                                                                                                                                  
    "nat_inside": null,                                                                                                                                                                       
    "nat_outside": null,                                                                                                                                                                      
    "dns_name": "",                                                                                                                                                                           
    "description": "",                                                                                                                                                                        
    "tags": [],                                                                                                                                                                               
    "custom_fields": {                                                                                                                                                                        
        "cnames": null                                                                                                                                                                        
    },                                                                                                                                                                                        
    "created": "2020-09-04",                                                                                                                                                                  
    "last_updated": "2020-09-04T17:59:56.904919-04:00"                                                                                                                                        
}

Save the ID of the IP that you just created (45731 here)
3. GET the ID of the IP that you created. The assigned_object_id is missing:

$ curl -X GET -H "Authorization: Token $TOKEN" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" https://$NETBOX/api/ipam/ip-addresses/45731/ 
{                                                                                                                                                                                             
    "id": 45731,                                                                                                                                                                              
    "url": "https:/$NETBOX/api/ipam/ip-addresses/45731/",                                                                                                              
    "family": {                                                                                                                                                                               
        "value": 4,                                                                                                                                                                           
        "label": "IPv4"                                                                                                                                                                       
    },                                                                                                                                                                                        
    "address": "1.2.3.4/32",                                                                                                                                                                  
    "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": "",                                                                                                                                                                           
    "description": "",                                                                                                                                                                        
    "tags": [],                                                                                                                                                                               
    "custom_fields": {                                                                                                                                                                        
        "cnames": null                                                                                                                                                                        
    },                                                                                                                                                                                        
    "created": "2020-09-04",                                                                                                                                                                  
    "last_updated": "2020-09-04T17:59:56.904919-04:00"                                                                                                                                        
}

Expected Behavior

The assigned_object_id field to be set after creating an IP and passing the field

Observed Behavior

The value was null

Originally created by @fantasmita on GitHub (Sep 5, 2020). <!-- NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED. This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report, and that any plugins have been disabled. --> ### Environment * Python version: 3.6.5 * NetBox version: 2.9.3 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. Get the ID of a existing interface object (`74005` in my example here) 2. Create an IP address and set that ID value to the `assigned_object_id` via ``` curl -X POST -H "Authorization: Token $TOKEN" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" https://$NETBOX/api/ipam/ip-addresses/ --data '{"address": "1.2.3.4/32", "assigned_object_id": 74005}' ``` In the returned JSON, you will see the `assigned_object_id` set correctly like this: ``` { "id": 45731, "url": "https://$NETBOX/api/ipam/ip-addresses/45731/", "family": { "value": 4, "label": "IPv4" }, "address": "1.2.3.4/32", "vrf": null, "tenant": null, "status": { "value": "active", "label": "Active" }, "role": null, "assigned_object_type": null, "assigned_object_id": 74005, "assigned_object": null, "nat_inside": null, "nat_outside": null, "dns_name": "", "description": "", "tags": [], "custom_fields": { "cnames": null }, "created": "2020-09-04", "last_updated": "2020-09-04T17:59:56.904919-04:00" } ``` Save the ID of the IP that you just created (`45731` here) 3. GET the ID of the IP that you created. The `assigned_object_id` is missing: ``` $ curl -X GET -H "Authorization: Token $TOKEN" -H "Content-Type: application/json" -H "Accept: application/json; indent=4" https://$NETBOX/api/ipam/ip-addresses/45731/ { "id": 45731, "url": "https:/$NETBOX/api/ipam/ip-addresses/45731/", "family": { "value": 4, "label": "IPv4" }, "address": "1.2.3.4/32", "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": "", "description": "", "tags": [], "custom_fields": { "cnames": null }, "created": "2020-09-04", "last_updated": "2020-09-04T17:59:56.904919-04:00" } ``` <!-- What did you expect to happen? --> ### Expected Behavior The `assigned_object_id` field to be set after creating an IP and passing the field <!-- What happened instead? --> ### Observed Behavior The value was `null`
adam closed this issue 2025-12-29 18:32:57 +01:00
Author
Owner

@haxorof commented on GitHub (Sep 8, 2020):

I just tested similar on 2.9.3 but then also set assigned_object_type to virtualization.vminterface since it was for a virtual machine.

@haxorof commented on GitHub (Sep 8, 2020): I just tested similar on 2.9.3 but then also set `assigned_object_type` to `virtualization.vminterface` since it was for a virtual machine.
Author
Owner

@jeremystretch commented on GitHub (Sep 8, 2020):

Both assigned_object_type and assigned_object_id must be set.

@jeremystretch commented on GitHub (Sep 8, 2020): Both `assigned_object_type` _and_ `assigned_object_id` must be set.
Author
Owner

@fantasmita commented on GitHub (Sep 8, 2020):

Ah, you're right. Setting both the assigned_object_id and the assigned_object_type works as expected. Sorry for the noise!

@fantasmita commented on GitHub (Sep 8, 2020): Ah, you're right. Setting both the `assigned_object_id` and the `assigned_object_type` works as expected. Sorry for the noise!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4070