netbox-community / go-netbox

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

not working with netbox v2.6.2 #116

Closed kplimack closed 3 years ago

kplimack commented 3 years ago

When I make any get/list request to the API (using the example code from github README), I get unmarshal errors

panic: Error getting ipam.prefixes: json: cannot unmarshal number into Go struct field PrefixStatus.results.status.value of type string

Looking at the JSON response from Netbox, it looks like its getting back an int that its not casting to a string for "value"

      "status": {
        "value": 1,
        "label": "Active"
      },
apeace commented 3 years ago

I am seeing a similar problem, using Netbox v2.10.4:

// (When 1234 and 5678 are valid rear/front ports)
terminationAType := "dcim.rearport"
var rearPort int64 = 1234
terminationBType := "dcim.frontport"
var frontPort int64 = 5678
label := "foo"
cableParams := dcim.NewDcimCablesCreateParams()
cableParams.Data = &models.WritableCable{
    TerminationaType: &terminationAType,
    TerminationaID:   &rearPort,
    TerminationbType: &terminationBType,
    TerminationbID:   &frontPort,
    Label:            label,
}
_, err := nb.Dcim.DcimCablesCreate(cableParams, nil)
if err != nil {
    fmt.Println(err)
}

Prints:

cannot unmarshal number into Go struct field Cable.termination_a of type string

The cable gets successfully created in Netbox and via Wireshark I can see the expected response. It seems whatever data definition go-netbox is using is incorrect.

Let me know if this should be filed as a separate issue.