Skip to content

Wrong type definition for interface link_peers  #151

Closed
@thunderstorm99

Description

@thunderstorm99

We're using go-netbox (github.com/netbox-community/go-netbox/v3 v3.4.5) in our go program. We are trying to list Interfaces using the function Dcim.DcimInterfacesList.

Our code to do this is:

func (nb netboxapi) getInterfacesFromDevice(deviceID int64) error {
	// create a string to be used on API call for the deviceID
	devID := fmt.Sprintf("%d", deviceID)

	// call API to get Interfaces for this device
	list, err := nb.Dcim.DcimInterfacesList(&dcim.DcimInterfacesListParams{
		Context:  context.Background(),
		DeviceID: &devID,
	}, nil)

	if err != nil {
		return fmt.Errorf("can't get Interfaces from Device %d, error is:\n\t-> %s", deviceID, err)
	}

	... more code ...
	return nil
}

The error is the following:

json: cannot unmarshal object into Go struct field Interface.results.link_peers of type string

I looked at the API by querying our Netbox instance at api/dcim/interfaces/?device_id=2345 which returns the following (truncated to only show link_peers)

...
"link_peers": [
  {
    "id": 1234,
    "url": "https://abc.def.ghi/api/dcim/interfaces/1234/",
    "display": "ge-0/0/8",
    "device": {
      "id": 2345,
      "url": "https://netbox-test.ps-intern.de/api/dcim/devices/2345/",
      "display": "xxxxxxxx",
      "name": "xxxxxxxx"
    },  
    "name": "ge-0/0/8",
    "cable": 3456,
    "_occupied": true
  }
]
...

Looking at the code for go-netbox it looks like the expected return value is of type []*string

LinkPeers []*string `json:"link_peers"`

This does not seem to coincide with the actual json response coming from netbox (tested both on netbox 3.3.10, as well as 3.4.5).
The source code for netbox also doesn't seem to use a []*string at that location
https://github.com/netbox-community/netbox/blob/85f40bcbe073ab8025a1d8afe7ffed08c002d7b8/netbox/dcim/models/device_components.py#L169-L174

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions