go-netbox icon indicating copy to clipboard operation
go-netbox copied to clipboard

Unexpected error return from IpamPrefixesList

Open tgoodsell-tempus opened this issue 1 year ago • 1 comments
trafficstars

When running the following function:

package main

import (
	"context"
	"log"
	"os"

	"github.com/netbox-community/go-netbox/v4"
)

func main() {
	ctx := context.Background()

	client := netbox.NewAPIClientFor("https://netbox.zro.gcp.tempus.cloud", os.Getenv("NETBOX_API_TOKEN"))

	prefixList, resp, err := client.IpamAPI.IpamPrefixesList(ctx).Execute()
	if err != nil {
		log.Printf("Num returned: %d", len(prefixList.Results))
		log.Printf("HTTP RESP: %v", resp)
		log.Fatalf("Failed to get prefixes: %v", err)
	}
}

I'm seeing results where:

  • preflxList has no results
  • RESP is a 200 return with the expected prefix outputs in the JSON body
  • The value of the err returned is: no value given for required property prefix_count

Netbox version being run: v4.0.3

Based on the value of the response, I gather this is an issue with the parsing of this request, rather than an actual API issue.

tgoodsell-tempus avatar Jun 04 '24 22:06 tgoodsell-tempus

I have the same problem with IpamIpRangesList and no value given for required property prefix_count.

I think the error in on the response parsing, role.prefix_count in my case (vrf.prefix_count in your's) is marked as required in OpenAPI spec but are not returned by the API:

GET /api/ipam/ip-ranges/?status=active

HTTP 200 OK
Allow: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 1,
            "url": "https://demo.netbox.dev/api/ipam/ip-ranges/1/",
            "display_url": "https://demo.netbox.dev/ipam/ip-ranges/1/",
            "display": "192.168.1.0-49/22",
            "family": {
                "value": 4,
                "label": "IPv4"
            },
            "start_address": "192.168.1.0/22",
            "end_address": "192.168.1.49/22",
            "size": 50,
            "vrf": null,
            "tenant": null,
            "status": {
                "value": "active",
                "label": "Actif"
            },
            "role": {
                "id": 5,
                "url": "https://demo.netbox.dev/api/ipam/roles/5/",
                "display": "Testing",
                "name": "Testing",
                "slug": "testing",
                "description": ""
            },
            "description": "Future use",
            "comments": "",
            "tags": [],
            "custom_fields": {},
            "created": "2021-12-30T00:00:00Z",
            "last_updated": "2024-10-25T11:11:26.071302Z",
            "mark_utilized": false
        }
    ]
}

vlaborie avatar Oct 25 '24 11:10 vlaborie

Fixed in #194

nutgood avatar Jan 24 '25 14:01 nutgood