Sites and Places
Outcome: the top of the map exists — a site, created through the API and read back — and the pattern every later record follows is established. A site in NetBox is a place where equipment lives: a building, a room, a cabinet row, a fenced yard with a hut. Everything physical hangs under a site eventually, so the map starts here.
A site, made and read back
The lab created its site through the REST API (chapter 9 explains the token in the header; the shape of the call is what matters here):
curl -s -H "Authorization: Bearer nbt_<key>.<token>" \
-H "Content-Type: application/json" \
-X POST http://127.0.0.1:18080/api/dcim/sites/ \
-d '{"name":"Example North Lab","slug":"example-north-lab",
"description":"Invented fixture site for the guide lab"}'
The answer is the created record, with the ID NetBox assigned it:
HTTP 201
and reading it back by that ID returns
the same record — name, slug,
description, and the URLs of both its
web page and its API form (transcript
t08-api-proof.txt, steps 1 and 10).
Everything in NetBox's API follows this
rhythm: POST a JSON description, get
the record with its ID, GET it again
whenever you need the truth.
The slug: the site's second name
Every site carries both a name, which humans read and which can change, and a slug — the small, URL-safe, unchanging identifier: lowercase, hyphens, no spaces. The slug is what appears in addresses and what scripts should hold on to. Slugs are unique, and NetBox enforces it: ask for a second site whose slug is taken and the creation is refused, with the field named in the answer:
{"slug":["site with this slug already exists."]}
HTTP 400
(Transcript t09-ui-login-and-refusals.txt.)
That small refusal is the spreadsheet
problem being solved in front of you: a
sheet would have let the duplicate in.
Below the site: locations and racks
Two more levels exist for when a place has structure, described here from the model rather than the lab (the lab's invented site is one room and needed neither):
- A location is a subdivision of a site — a floor, a room, a row. Locations nest, so a room can live inside a floor inside the site.
- A rack is the cabinet itself: it belongs to a site (and optionally a location), has a height in rack units, and devices mounted in it record which units they occupy — the record that makes "is there space in rack 4" a question with an answer.
Regions sit above sites for organisations spread over geography — a tree of areas that sites belong to. Small networks skip all three levels without penalty; NetBox's model lets you add structure when the map needs it, not before.
The check
Your site exists when both doors show
it: the web page under DCIM → Sites
shows the row, and the API read —
GET /api/dcim/sites/ — returns a
count of 1 with your slug in it. The
lab's read-backs are steps 1 and 10 of
t08-api-proof.txt.