1

How to work with go-netbox client

Hi, i want to send data to netbox using go-netbox client.

    client := netbox.NewNetboxWithAPIKey("netbox.example.org", "<api-token>")

    ipaddress := "192.168.0.100"
    ipAddress := &models.IPAddress{
        Address:    &ipaddress, 
        Description: "Example IP Address",
    }

    createdIPAddress, err := client.Ipam.IpamIPAddressesCreate(ipAddress, ?)

What i need to pass to authInfo ?

Data909
  • 11
  • 2

1 Answers1

0

You can just pass nil to it.

When the client is created with an API key, this API key will be used to issue requests. So it's OK to pass nil to the func. See the source code where a default runtime.ClientAuthInfoWriter is created.

If the client is created without feeding the API key and you need to provide a runtime.ClientAuthInfoWriter to a func, you can create one like this:

import (
    "fmt"

    "github.com/go-openapi/runtime/client"
)

var apiKeyAuth = runtime.APIKeyAuth("Authorization", "header", fmt.Sprintf("Token %v", apiToken))

References:

  1. Authenticating to the API:

    An authentication token is attached to a request by setting the Authorization header to the string Token followed by a space and the user's token

  2. github.com/go-openapi/runtime/client: see the list of funcs that return a runtime.ClientAuthInfoWriter.

Zeke Lu
  • 6,349
  • 1
  • 17
  • 23