Replies: 4 comments 2 replies
-
you need the assigned_object_type along with the assigned_object_id as IPs can be assigned to Interfaces, VMInterfaces and FHRP Groups so you have to tell it which related object the ID is for. assigned_object_id=1234 could be a row in any of those tables, it's gotta know which one.
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: fatman00 ***@***.***>
Sent: Thursday, December 8, 2022 7:26 AM
To: netbox-community/netbox ***@***.***>
Cc: Subscribed ***@***.***>
Subject: [netbox-community/netbox] Unable to filter dcim.ip_addresses on assigned_object_id (Discussion #11136)
I want to find all IP addresses using the API that are bound to an interface.
I hoped to just add the querystring of assigned_object_id but the API just returns all IP addresses without filtering.
https://demo.netbox.dev/api/ipam/ip-addresses/?assigned_object_id=902
This will return all IP addresses and not just the one assigned to an object as show at index 1 below:
HTTP 200 OK
Allow: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"count": 181,
"next": "https://demo.netbox.dev/api/ipam/ip-addresses/?assigned_object_id=902&limit=50&offset=50",
"previous": null,
"results": [
{
"id": 181,
"url": "https://demo.netbox.dev/api/ipam/ip-addresses/181/",
"display": "10.20.30.44/32",
"family": {
"value": 4,
"label": "IPv4"
},
"address": "10.20.30.44/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": [],
"dns_name": "rwr-faxa01",
"description": "Ez naon faxa",
"tags": [],
"custom_fields": {},
"created": "2022-12-08T11:15:37.930845Z",
"last_updated": "2022-12-08T11:15:37.930875Z"
},
{
"id": 31,
"url": "https://demo.netbox.dev/api/ipam/ip-addresses/31/",
"display": "172.16.0.1/24",
"family": {
"value": 4,
"label": "IPv4"
},
"address": "172.16.0.1/24",
"vrf": {
"id": 1,
"url": "https://demo.netbox.dev/api/ipam/vrfs/1/",
"display": "Alpha (65000:100)",
"name": "Alpha",
"rd": "65000:100"
},
"tenant": null,
"status": {
"value": "active",
"label": "Active"
},
"role": {
"value": "carp",
"label": "CARP"
},
"assigned_object_type": "virtualization.vminterface",
"assigned_object_id": 902,
"assigned_object": {
"id": 902,
"url": "https://demo.netbox.dev/api/virtualization/interfaces/902/",
"display": "eth1",
"virtual_machine": {
"id": 361,
"url": "https://demo.netbox.dev/api/virtualization/virtual-machines/361/",
"display": "vm1",
"name": "vm1"
},
"name": "eth1"
},
"nat_inside": null,
"nat_outside": [],
"dns_name": "112",
"description": "Proxmox",
"tags": [
{
"id": 21,
"url": "https://demo.netbox.dev/api/extras/tags/21/",
"display": "Uniform",
"name": "Uniform",
"slug": "uniform",
"color": "ff5722"
}
],
"custom_fields": {},
"created": "2022-04-08T00:25:21.668000Z",
"last_updated": "2022-12-08T06:31:30.966307Z"
},
—
Reply to this email directly, view it on GitHub<#11136>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UM4WHYMDHA6P7IYJ7WTWMHOYDANCNFSM6AAAAAASYENKQM>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Adding the type does not seem to help me:
|
Beta Was this translation helpful? Give feedback.
-
I didn't read through the doc before shooting my mouth off, there is a separate query parameter for each assigned_object_type so you only need to pass one thing. The api return format isn't the exact same format as the query fields
https://demo.netbox.dev/api/docs/
eg https://demo.netbox.dev/ipam/ip-addresses/?vminterface_id=902
—
Mark Tinberg ***@***.***>
Division of Information Technology-Network Services
University of Wisconsin-Madison
…________________________________
From: fatman00 ***@***.***>
Sent: Thursday, December 8, 2022 10:54 AM
To: netbox-community/netbox ***@***.***>
Cc: Mark Tinberg ***@***.***>; Comment ***@***.***>
Subject: Re: [netbox-community/netbox] Unable to filter dcim.ip_addresses on assigned_object_id (Discussion #11136)
Adding the type does not seem to help me:
https://demo.netbox.dev/api/ipam/ip-addresses/?assigned_object_id=1222&assigned_object_type=dcim.interface
HTTP 200 OK
Allow: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept
{
"count": 188,
<output omitted>
—
Reply to this email directly, view it on GitHub<#11136 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AAS7UM63AAKETR2XZLOVJR3WMIHC7ANCNFSM6AAAAAASYENKQM>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I had the exact same issue and Mark's answer helped but the link to the docs doesn't work anymore and I was unable to find this specific curiosity in any Netbox docs. Is there a documentation (aside from https://demo.netbox.dev/static/docs/rest-api/filtering/) where one would find these otherwise indeducible field names? |
Beta Was this translation helpful? Give feedback.
-
I want to find all IP addresses using the API that are bound to an interface.
I hoped to just add the querystring of assigned_object_id but the API just returns all IP addresses without filtering.
https://demo.netbox.dev/api/ipam/ip-addresses/?assigned_object_id=902
This will return all IP addresses and not just the one assigned to an object as show at index 1 below:
Beta Was this translation helpful? Give feedback.
All reactions