netbox-community / go-netbox

The official Go API client for Netbox IPAM and DCIM service.
Other
194 stars 144 forks source link

IPAM IP Addresses Error/bug: 400] map[tags:[All list items must be of string type.]]) #99

Closed erikkn closed 3 years ago

erikkn commented 3 years ago

Hi folks,

Please consider the following snippet:

 12 func main() {
 13     conn := netbox.NewNetboxWithAPIKey("127.0.0.1:8000", "0123456789abcdef0123456789abcdef01234567") // Making debugging easier ;)
 14     c := conn.Ipam
 15     
 16     var tagList []*models.NestedTag
 17     tags := []string{"test1", "test2"}
 18     address := "10.0.0.3/32"
 19         
 20     for _, v := range tags {
 21         tagItem := models.NestedTag{Name: &v}
 22         tagList = append(tagList, &tagItem)
 23     }
 24     
 25     params := ipam.NewIpamIPAddressesCreateParams()
 26     params.WithData(&models.WritableIPAddress{
 27         Address: &address,
 28         Tags:    tagList,
 29     })
 30     
 31     ip, err := c.IpamIPAddressesCreate(params, nil)
 32     if err != nil {
 33         log.Fatalf("Error creating IP Address: ", err)
 34     }
 35 
 36     fmt.Println(ip.Payload.ID)
 37 }

I am pretty new to the scene, so forgive the ugliness, but this results in the following error:

Error creating IP Address: %!(EXTRA *ipam.IpamIPAddressesCreateDefault=[POST /ipam/ip-addresses/][400] ipam_ip-addresses_create default  map[tags:[All list items must be of string type.]])
exit status 1

I believe this error is related to the 'type' change that got introduced in PR#92 (https://github.com/netbox-community/go-netbox/pull/92). This PR changes the type of the Tags field of the 'netbox/models/writable_ip_address.go' file from []string to []NestedTag. (cc @awlx)

I am happy to open a PR and revert the type change, but as I mentioned, I am pretty new and I would like to receive some feedback on this first :).

Cheers,

erikkn commented 3 years ago

cc @awlx (not sure if you receive a notification if I mention/tag you in the description box).

awlx commented 3 years ago

Oh, seems really like the issue. But I think we use it as []NestedTag in our code. But let me check. Happy to take a PR @erikkn

//Edit: See below are you running Netbox 2.9?

awlx commented 3 years ago

So according to the netbox API this is a []NestedTag for Netbox 2.9

Screenshot 2020-10-01 at 14 52 10 Screenshot 2020-10-01 at 14 52 05

erikkn commented 3 years ago

Thanks for your reply! Will look into it later today, but I am pretty sure you are right

erikkn commented 3 years ago

@awlx , you are absolutely right! Thanks for your help!

I really thought I was running Netbox >=2.9, turned out I was running version 2.8.4 :man_facepalming: . For the sake of completion, this code works:

     test2 := []*models.NestedTag{{Name: &name, Slug: &slug}
     params := ipam.NewIpamIPAddressesCreateParams()
     params.WithData(&models.WritableIPAddress{
         Address: &address,
         Tags:    test2,
     })