netbox-cli 0.2.1

full-featured cli client for the netbox api
netbox-cli-0.2.1 is not a library.

netbox-cli

full-featured cli for the netbox api. covers standard crud resources and a raw mode for any endpoint.

install

from crates.io:

cargo install netbox-cli

from this repo:

cargo install --path crates/netbox-cli

quickstart

netbox-cli --url https://netbox.example.com --token $TOKEN dcim devices list

auth

required:

  • --url
  • --token

or set:

  • NETBOX_URL
  • NETBOX_TOKEN

resources

list resource groups:

netbox-cli resources
netbox-cli resources dcim

common commands

list:

netbox-cli dcim devices list
netbox-cli ipam prefixes list
netbox-cli vpn tunnels list

get by id:

netbox-cli dcim devices get 42

create/update with json:

netbox-cli circuits circuits create --json '{"cid":"CIR-1001","provider":1,"type":1}'
netbox-cli virtualization virtual-machines update 42 --file vm-update.json

output formats

netbox-cli dcim devices list --output json
netbox-cli dcim devices list --output yaml
netbox-cli dcim devices list --output table

select a field with a dot path:

netbox-cli dcim devices list --select results
netbox-cli dcim devices list --select results.name

table output flattens paginated responses by showing the results rows and a summary line with count/next/previous when present.

dry run

print the request for write operations without sending them:

netbox-cli dcim devices create --json '{"name":"switch-01","device_type":1,"role":1,"site":1}' --dry-run

raw requests

use raw for any endpoint:

netbox-cli raw --method GET --path dcim/devices/ --query "name=leaf-1" --query "limit=5"
netbox-cli raw --method POST --path ipam/vrfs/ --json '{"name":"blue","rd":"65000:100"}'

notes:

  • --path is api-relative, e.g. dcim/devices/
  • a leading api/ is stripped if present
  • repeat --query key=value for multiple params

graphql

read-only graphql queries:

netbox-cli graphql --query '{ devices { name } }'
netbox-cli graphql --query-file ./query.graphql --vars '{"limit":5}'

special endpoints

netbox-cli extras-dashboard get
netbox-cli core-background-queues list
netbox-cli users-config
netbox-cli plugin-branch-action 1 merge --json '{"commit":true}'

output

responses are json, pretty-printed to stdout. errors return non-zero exit codes.

exit codes:

  • 0 success
  • 1 request or parsing error
  • 2 invalid command or arguments

errors include http status, path, and request id when available.

help

netbox-cli --help
netbox-cli dcim --help