API filtering for IPAM: filters for assigned_object_id and assigned_object_type are ignored #4984

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

Originally created by @jogulin on GitHub (Jun 9, 2021).

NetBox version

v2.11.3

Python version

3.6

Steps to Reproduce

Run the following command (replace the "$token" value as appropriate for your authentication, and adjust the URL as appropriate)

curl -v -k -X GET \
-H "Authorization: Token $token" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
"https://netbox.local/api/ipam/ip-addresses/?assigned_object_id=367&assigned_object_type='dcim.interface'&limit=1"

Expected Behavior

Expect back either a single object that matches both filter conditions or an empty set

Observed Behavior

Got back the following results:

{
    "count": 1687,
    "next": "http://netbox.local/api/ipam/ip-addresses/?assigned_object_id=367&assigned_object_type=%27dcim.interface%27&limit=1&offset=1",
    "previous": null,
    "results": [
        {
            "id": 321,
            "url": "http://netbox.local/api/ipam/ip-addresses/87/",
            "display": "10.100.0.7/24",
            "family": {
                "value": 4,
                "label": "IPv4"
            },
            "address": "10.100.0.7/24",
            "vrf": null,
            "tenant": {
                "id": 24,
                "url": "http://netbox.local/api/tenancy/tenants/1/",
                "display": "Tenant 1",
                "name": "Tenant 1",
                "slug": "tenant-1"
            },
            "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": "unexpected.local",
            "description": "",
            "tags": [],
            "custom_fields": {},
            "created": "2020-01-15",
            "last_updated": "2020-07-08T21:25:26.614917Z"
        }
    ]
}

The count equates to the number of IP addresses currently stored in the IPAM portion of Netbox. This would be no different than doing a GET request for all of the IP addresses every time and then manually searching each one until I found whether or not what I was searching for actually exists. In the example I provided, we have an IP address that is entered but is not assigned to any device or virtual machine.

Originally created by @jogulin on GitHub (Jun 9, 2021). ### NetBox version v2.11.3 ### Python version 3.6 ### Steps to Reproduce Run the following command (replace the "$token" value as appropriate for your authentication, and adjust the URL as appropriate) ```bash curl -v -k -X GET \ -H "Authorization: Token $token" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ "https://netbox.local/api/ipam/ip-addresses/?assigned_object_id=367&assigned_object_type='dcim.interface'&limit=1" ``` ### Expected Behavior Expect back either a single object that matches both filter conditions or an empty set ### Observed Behavior Got back the following results: ```json { "count": 1687, "next": "http://netbox.local/api/ipam/ip-addresses/?assigned_object_id=367&assigned_object_type=%27dcim.interface%27&limit=1&offset=1", "previous": null, "results": [ { "id": 321, "url": "http://netbox.local/api/ipam/ip-addresses/87/", "display": "10.100.0.7/24", "family": { "value": 4, "label": "IPv4" }, "address": "10.100.0.7/24", "vrf": null, "tenant": { "id": 24, "url": "http://netbox.local/api/tenancy/tenants/1/", "display": "Tenant 1", "name": "Tenant 1", "slug": "tenant-1" }, "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": "unexpected.local", "description": "", "tags": [], "custom_fields": {}, "created": "2020-01-15", "last_updated": "2020-07-08T21:25:26.614917Z" } ] } ``` The count equates to the number of IP addresses currently stored in the IPAM portion of Netbox. This would be no different than doing a GET request for all of the IP addresses every time and then manually searching each one until I found whether or not what I was searching for actually exists. In the example I provided, we have an IP address that is entered but is not assigned to any device or virtual machine.
adam closed this issue 2025-12-29 19:22:52 +01:00
Author
Owner

@jogulin commented on GitHub (Jun 10, 2021):

In addition, if I use either "assigned_object_type" or "assigned_object_id" as a filter I get the same results. Using "assigned_object_id" alone I would expect 0, 1, or 2 results (it's possible that the same ID could exist as both a dcim.interface and virtualization.vminterface).

@jogulin commented on GitHub (Jun 10, 2021): In addition, if I use either "assigned_object_type" or "assigned_object_id" as a filter I get the same results. Using "assigned_object_id" alone I would expect 0, 1, or 2 results (it's possible that the same ID could exist as both a dcim.interface and virtualization.vminterface).
Author
Owner

@jeremystretch commented on GitHub (Jun 10, 2021):

assigned_object_type and assigned_object_id aren't supported filters per the REST API documentation. Instead, you can use interface_id and vminterface_id to filter IP addresses by their assignment to device and VM interfaces, respectively.

@jeremystretch commented on GitHub (Jun 10, 2021): `assigned_object_type` and `assigned_object_id` aren't supported filters per the REST API documentation. Instead, you can use `interface_id` and `vminterface_id` to filter IP addresses by their assignment to device and VM interfaces, respectively.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4984