What are we doing?
- Connecting to Netbox
- Fetching devices
- Printing a short preview
Prerequisites
- NetBox URL is reachable from the Netpicker job runner.
- Use the site base URL (e.g., https://netbox.example.com). Do not include /api
- If NetBox lives behind a path, include it (e.g., https://portal.example.com/netbox)
- NetBox API token with at least read access to DCIM → Devices.
- Netpicker can run jobs (UI access) and you can select any device when launching the job (even for read‑only jobs)
- The runner may require a target device context; the code may ignore it.
Environment variables
Netpicker injects a netbox client when these env vars are present in the worker processes:
- NETBOX_API — NetBox base URL (or API root)
- NETBOX_TOKEN — NetBox API token with DCIM read access
Option A — docker-compose.yml (use a shared anchor)
x-api: &api_common
environment:
NETBOX_API: "https://netbox.example.com/" # base URL or API root
NETBOX_TOKEN: "wersdf…."
services:
api:
<<: *api_common
celery:
<<: *api_common
agent:
<<: *api_common
Option B — docker-compose.override.yml (preferred)
If updated in docker-compose.override.yml ensure to define NetBox env explicitly under both api and celery:
services:
api:
environment:
NETBOX_API: "https://netbox.example.com/"
NETBOX_TOKEN: "wersdf….}"
celery:
environment:
NETBOX_API: "https://netbox.example.com/"
NETBOX_TOKEN: "wersdf…."
The job
In the Netpicker UI, go to Automation → Jobs, create a new job named netbox_hello, paste the code below, and Save.
from comfy.automate import job
@job()
def netbox_hello(netbox, preview=25):
if netbox is None:
raise RuntimeError("NetBox integration not available. Check NETBOX_API/NETBOX_TOKEN.")
try:
preview = int(preview) if str(preview).strip() else 25
except Exception:
preview = 25
names = []
for d in netbox.dcim.devices.all():
n = getattr(d, "name", None) or getattr(d, "display", None) or getattr(d, "id", None)
if n:
names.append(str(n))
names.sort(key=str.lower)
shown = min(preview, len(names))
if shown:
print("PREVIEW:", ", ".join(names[:shown]))
print(f"Total devices: {len(names)} (showing {shown})")
Screenshots from the lab setup:
Netbox env settings
Updated in docker-compose.override.yml with NetBox env under both api and celery:

Creating the Job
Open Jobs → Automation → Jobs → Create Job

- Python Job
- Use the code mentioned under The Job section of this article

- Click Save
While saving it prompts for Name: netbox_hello
Running the job
- Select any device (Needed to execute the runner, no action performed on the device)
- Set params (optional):
- preview → e.g., 25
- Click Run (You can also do Dry Run, you would be able to see the result in same page)


