netbox-community / go-netbox

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

Cannot parse created date into time #148

Closed FunTimeCoding closed 1 year ago

FunTimeCoding commented 1 year ago

I'm trying to make basic use of this library. When loading sites or devices, I get this:

parsing time "2020-09-10" as "2006-01-02 15:04:05": cannot parse "" as "15"

With DEBUG, this field might be the cause:

"created":"2020-09-10"

I passed in a formatter without success. What am I missing?

v0ctor commented 1 year ago

Could you provide a code example to replicate the error? Moreover, which version are you using?

FunTimeCoding commented 1 year ago

Code:

func Example(configuration monitor.Configuration) {
    transport := secureTransport.New(
        configuration.NetBoxHost,
        netBoxClient.DefaultBasePath,
        []string{"https"},
    )
    transport.DefaultAuthentication = secureTransport.APIKeyAuth(
        "Authorization",
        "header",
        fmt.Sprintf("Token %v", configuration.NetBoxToken),
    )
    formats := strfmt.NewFormats()
    client := netBoxClient.New(transport, formats)

    siteParameters := dcim.NewDcimSitesListParams()
    siteList, siteListFail := client.Dcim.DcimSitesList(
        siteParameters,
        nil,
    )
    monitor.FatalOnError(siteListFail)
    log.Print(siteList)
}

go-netbox version: 3.4.5 netbox version: 3.1.11

FunTimeCoding commented 1 year ago

I believe I figured out how to downgrade a dependency. Using version 3.2 shows the same error. 3.1 doesn't exist. But with 3.0 it works.

v0ctor commented 1 year ago

Now there is a release for Netbox 3.1: v3.1.11-0.

Could you try it? With this version you should have full compatibility.

FunTimeCoding commented 1 year ago

I changed the version like this: go get github.com/netbox-community/v3/go-netbox@v3.1.11-0

But with my example request I ran into an error: 2023/03/03 14:31:17 json: cannot unmarshal object into Go struct field DeviceWithConfigContext.results.config_context of type string

Looking at it with DEBUG (I redacted this) - Its essentially a JSON object, not a string. "config_context":{"installserver":{"saltgrains":{"somekey":"somevalue"},"network":{"domain":"example.org","gateway":"172.20.0.1","options":{"timeout":"1","attempts":"1"},"nameservers":["172.20.0.1","172.20.0.2"]},"partitioning":"plain:/dev/sda#swap:8192:swap#/:*:ext4","salt_master":["salt.example.org"]}}

FunTimeCoding commented 1 year ago

@v0ctor Lets close this, as 3.0 works for me?

v0ctor commented 1 year ago

As the error is caused by the OpenAPI spec, 3.0 works for you and the OpenAPI 3.0 spec of Netbox is going to be released soon (which will probably fix these common errors), let's close the issue.