New API endpoint: /api/ipam/prefixes/<int:pk>/ip-ranges/ #9332

Closed
opened 2025-12-29 20:48:38 +01:00 by adam · 4 comments
Owner

Originally created by @tmalkowski on GitHub (Mar 8, 2024).

NetBox version

v3.3.8

Feature type

New functionality

Proposed functionality

Create new API endpoint to match web UI endpoint /ipam/prefixes/<int:pk>/ip-ranges/ — results would be the same as /api/ipam/ip-ranges/<int:pk>/.

Use case

I am trying to dynamically build DHCP configuration: prefix = dhcp subnet, IP range = dynamic IP pool. Currently, I would need to fetch all IP ranges and then determine which prefix contains the start IP for each range and the dhcp role. This adds more overhead than it seems should be necessary.

Database changes

No response

External dependencies

No response

Originally created by @tmalkowski on GitHub (Mar 8, 2024). ### NetBox version v3.3.8 ### Feature type New functionality ### Proposed functionality Create new API endpoint to match web UI endpoint `/ipam/prefixes/<int:pk>/ip-ranges/` — results would be the same as `/api/ipam/ip-ranges/<int:pk>/`. ### Use case I am trying to dynamically build DHCP configuration: prefix = dhcp subnet, IP range = dynamic IP pool. Currently, I would need to fetch all IP ranges and then determine which prefix contains the start IP for each range and the dhcp role. This adds more overhead than it seems should be necessary. ### Database changes _No response_ ### External dependencies _No response_
adam added the type: feature label 2025-12-29 20:48:38 +01:00
adam closed this issue 2025-12-29 20:48:38 +01:00
Author
Owner

@tmalkowski commented on GitHub (Mar 8, 2024):

Alternative would be if I could search for IP ranges only in a certain network: /api/ipam/ip-ranges/?prefix_id=<int:pk> or /api/ipam/ip-ranges/?parent=10.20.30.0%2F24

@tmalkowski commented on GitHub (Mar 8, 2024): Alternative would be if I could search for IP ranges only in a certain network: `/api/ipam/ip-ranges/?prefix_id=<int:pk>` or `/api/ipam/ip-ranges/?parent=10.20.30.0%2F24`
Author
Owner

@jeremystretch commented on GitHub (Mar 8, 2024):

Create new API endpoint to match web UI endpoint /ipam/prefixes/<int:pk>/ip-ranges/

This is considered an anti-pattern in REST API design: Instead, every type of object has its own designated endpoint. For IP ranges, this is /api/ipam/ip-ranges/. This endpoint can be filtered using the parent and vrf query parameters to return only ranges contained by a specified prefix and VRF. For example:

GET /api/ipam/ip-ranges/?parent=192.168.1.0/25
@jeremystretch commented on GitHub (Mar 8, 2024): > Create new API endpoint to match web UI endpoint `/ipam/prefixes/<int:pk>/ip-ranges/ ` This is considered an anti-pattern in REST API design: Instead, every type of object has its own designated endpoint. For IP ranges, this is `/api/ipam/ip-ranges/`. This endpoint can be filtered using the `parent` and `vrf` query parameters to return only ranges contained by a specified prefix and VRF. For example: ``` GET /api/ipam/ip-ranges/?parent=192.168.1.0/25 ```
Author
Owner

@tmalkowski commented on GitHub (Mar 8, 2024):

As far as I can tell, "parent" doesn't work on ip ranges.

@tmalkowski commented on GitHub (Mar 8, 2024): As far as I can tell, "parent" doesn't work on ip ranges.
Author
Owner

@jeremystretch commented on GitHub (Mar 8, 2024):

It does.

@jeremystretch commented on GitHub (Mar 8, 2024): [It does.](https://demo.netbox.dev/api/ipam/ip-ranges/?parent=192.168.1.0/25)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9332