REST API Network Mapper - edmozley/freeitsm GitHub Wiki

πŸ—ΊοΈ REST API: Network Mapper

The complete usage guide for the Network Mapper module of the REST API β€” diagrams, nodes, connectors, version snapshots and the suggestions feed. Mirrors the interactive documentation at System β†’ API β†’ Documentation (with its live "Try it" tester).

[!NOTE] New to the API? The basics table on REST API: Tickets covers base URL, authentication, the response envelope, error codes, rate limits and PATCH semantics β€” identical across all modules.

What's distinctive about Network Mapper:

πŸ€– Built for discovery agents The target consumer is an agentic network-discovery tool keeping diagrams alive: read what's drawn, ask what's missing, add the new switch, snapshot a version first. Stale network diagrams are the classic ITSM failure β€” this API is the fix.
🧠 Diagrams a machine can understand Nodes aren't anonymous boxes β€” each is bound to a CMDB object, and reads hydrate everything: the CI's name, class, effective icon, planned flag, optionally its full typed properties, plus each connector's endpoint objects and the CMDB relationship verb it represents, and a layout block with the canvas bounding box.
πŸ”§ Surgical edits with stable ids The editor can only save the whole canvas (regenerating every node id). The API adds incremental operations β€” add/move/restyle/remove a single node or connector β€” and the ids stay stable, so an agent can track elements across edits.
🧲 Think in CIs, not node ids Connectors accept from_object_id/to_object_id, and cmdb_relationship_id: "auto" binds the drawn line to the real CMDB relationship between the two objects. Omitted x/y coordinates auto-place in a tidy column for a human to arrange later.
πŸ•°οΈ Versions as undo points The module's linear version chain: only the newest (leaf) version is editable, history is frozen. POST .../versions snapshots before automated changes β€” a free rollback point for cautious agents.

πŸš€ Quick start β€” the discovery-agent loop

B="https://your-server/api/v1"; K="Authorization: Bearer fitsm_…"

# What's on the diagram? (full hydration: CIs, classes, verbs, layout)
curl -s "$B/network-diagrams/7?include_properties=true" -H "$K"

# What's missing? CMDB neighbours of drawn objects, not yet on the canvas
curl -s "$B/network-diagrams/7/suggestions" -H "$K"

# Snapshot first (free undo), then draw the newly discovered switch
NEW=$(curl -s -X POST "$B/network-diagrams/7/versions" -H "$K" \
  -H "Content-Type: application/json" -d '{"version_label": "auto-sync"}' | jq -r '.data.id')
curl -s -X POST "$B/network-diagrams/$NEW/nodes" -H "$K" -H "Content-Type: application/json" \
  -d '{"cmdb_object_id": 41}'          # x/y omitted β€” auto-placed
curl -s -X POST "$B/network-diagrams/$NEW/connectors" -H "$K" -H "Content-Type: application/json" \
  -d '{"from_object_id": 41, "to_object_id": 38, "cmdb_relationship_id": "auto"}'

πŸ—ΊοΈ Diagrams

🟒 GET /network-diagrams Β  πŸ”‘ network_diagrams.read

Current versions only by default (all_versions=true for frozen history), most recently updated first, with node/connector counts. Filters: q (titles + descriptions), contains_object_id (every diagram a given CI is drawn on β€” "which maps show this server?"), created_by, updated_since, pagination.

πŸ”΅ POST /network-diagrams Β  πŸ”‘ network_diagrams.create

title required. Optionally ship the whole initial drawing in one call:

{ "title": "Head office network",
  "nodes": [ { "cmdb_object_id": 1, "ref": "fw" },
             { "cmdb_object_id": 2, "ref": "sw1", "x": 300, "y": 100, "size": "large" } ],
  "connectors": [ { "from_ref": "fw", "to_ref": "sw1", "cmdb_relationship_id": "auto" } ] }

Nodes may carry a ref (any string) for connectors to reference; nodes without x/y are auto-placed. Also settable: paper_size/paper_orientation (A4/A3/A2/Letter/Tabloid), branding header/footer slots (null = inherit the org default).

🟒 GET /network-diagrams/{id} Β  πŸ”‘ network_diagrams.read

The full machine-legible drawing. Add ?include_properties=true for each object's typed CI property values:

{ "data": { "id": 7, "title": "Head office network", "is_current": true,
    "nodes": [ { "id": 224, "x": 100, "y": 100, "size": "medium", "size_px": 56,
                 "icon": "server", "icon_override": null,
                 "colour_override": "#dc2626", "w": 160, "h": 90, "style": { "bold": true },
                 "page_key": 0, "layer_key": 0, "group_key": "g1", "article_id": 42,
                 "object": { "id": 16, "name": "SQLSVR01", "is_planned": false,
                             "class": { "id": 12, "name": "Server", "icon": "server" } } } ],
    "connectors": [ { "id": 185,
        "from": { "node_id": 224, "object_id": 16, "object_name": "SQLSVR01", "shape_uid": null },
        "to":   { "node_id": 225, "object_id": 38, "object_name": "CORE-SW01", "shape_uid": null },
        "relationship": { "id": 21, "verb": "connects to", "inverse_verb": "is connected from" },
        "label": null, "line_style": "dashed", "style": null },
      { "id": 186,
        "from": { "node_id": null, "object_id": null, "object_name": null, "shape_uid": "k3x9a1" },
        "to":   { "node_id": 224, "object_id": 16, "object_name": "SQLSVR01", "shape_uid": null },
        "relationship": null, "label": "ISP", "line_style": "dotted",
        "style": { "colour": "#2563eb", "arrowEnd": "open" } } ],
    "shapes": [ { "uid": "k3x9a1", "shape_type": "cloud", "x": 400, "y": 60, "w": 140, "h": 80,
                  "rotation": 0, "text": "Internet", "style": null, "layer": "back", "z": 1,
                  "icon_id": null, "page_key": 0, "layer_key": 0, "group_key": null, "article_id": null } ],
    "pages":  [ { "page_key": 0, "name": "Overview", "sort": 0 } ],
    "layers": [ { "page_key": 0, "layer_key": 0, "name": "Layer 1", "sort": 0, "visible": true, "locked": false } ],
    "related_article_ids": [ 42 ],
    "layout": { "bounds": { "min_x": 100, "min_y": 100, "max_x": 316, "max_y": 156 },
                "width": 216, "height": 56,
                "node_sizes_px": { "small": 40, "medium": 56, "large": 80 } } } }

🟠 PATCH /network-diagrams/{id} Β  πŸ”‘ network_diagrams.update

Partial metadata update (title, description, version_label, paper, branding). Sending nodes and/or connectors switches to full contents replace β€” both sets are replaced and every node id regenerates, exactly like an editor save. For surgical edits, use the node/connector endpoints instead. A frozen historical version is a 409.

Drawing features (5.11.0). GET returns a node's own look and place (colour_override, w, h, style, page_key, layer_key, group_key, article_id), connectors whose end is a shape (shape_uid, with the node fields null), and the diagram's shapes, pages, layers and related_article_ids. They use the names PATCH accepts, so read, change one thing, write it back keeps everything - provided you send them back:

  • each node with the fields GET gave it, plus a ref (e.g. "n224") for connectors to point at;
  • each connector end as from_ref / to_ref, or from_shape_uid / to_shape_uid for a shape end, with its line_style and style;
  • shapes, pages and layers only if you change them - left out, they are kept as they are.

A node sent without its look goes back to the plain look on page 0. If all you need is one change, the single-node and single-connector endpoints below are simpler and leave everything else alone.

πŸ”΄ DELETE /network-diagrams/{id} Β  πŸ”‘ network_diagrams.delete

Leaf-only: deleting the current version resurfaces its parent as current ("discard this draft"). A version with newer history after it is a 409 β€” the UI lets that corrupt the chain; the API refuses. ?chain=true deletes the entire version chain, transactionally.


πŸ•°οΈ Versions

🟒 GET /network-diagrams/{id}/versions Β  πŸ”‘ network_diagrams.read

The whole chain containing this diagram, oldest first, with is_current flags.

πŸ”΅ POST /network-diagrams/{id}/versions Β  πŸ”‘ network_diagrams.create

Clones the current version forward β€” nodes, connectors, paper and branding all copied; the clone becomes editable and the source freezes (the editor's "New version"). title/description/version_label default to the source's. 409 unless called on the current version.


🧲 Suggestions

🟒 GET /network-diagrams/{id}/suggestions Β  πŸ”‘ network_diagrams.read

CMDB neighbours of on-diagram objects that aren't drawn yet β€” found via relationships in both directions and object_ref property links (one direction more than the module's own related-objects feed). Each suggestion carries everything needed to draw it:

{ "data": [ { "object": { "id": 39, "name": "CORE-RTR01", "is_planned": false,
                "class": { "id": 18, "name": "Network Device", "icon": "network" } },
              "via": [ { "kind": "relationship", "from_object_id": 38,
                         "label": "connects to", "relationship_id": 26 } ] } ] }

?object_id= scopes to one on-diagram object's neighbours; ?limit= caps results (default 50). An empty array means the diagram already shows everything the CMDB knows about.


πŸ”§ Nodes & connectors (incremental, stable ids)

All these require the current version (frozen history is a 409) and carry πŸ”‘ network_diagrams.update.

πŸ”΅ POST /network-diagrams/{id}/nodes

One node (body = the node) or a batch ({"nodes": [...]}). cmdb_object_id required; x/y optional (auto-placed in a fresh column right of the drawing); size small|medium|large; icon_override any key from GET /cmdb-icons. An object already on the diagram is a 409 unless allow_duplicate: true.

🟠 PATCH /network-diagrams/{id}/nodes/{node_id} Β  / Β  πŸ”΄ DELETE .../nodes/{node_id}

PATCH moves/restyles (x, y, size, icon_override β€” null reverts to the class icon), plus colour_override (#rrggbb), w / h (20-2000), style, page_key, layer_key and group_key. A field you don't send is left alone; null clears colour, size and style. DELETE removes the node and every connector touching it (count returned).

πŸ”΅ POST /network-diagrams/{id}/connectors

Endpoints by from_node_id/to_node_id or from_object_id/to_object_id (422 if the object isn't on the diagram, or is on it twice β€” disambiguate with node ids), or a shape by from_shape_uid/to_shape_uid (422 if no shape on the diagram has that uid). cmdb_relationship_id: an id, null, or "auto" (binds to the existing CMDB relationship between the two objects, either direction). Self-loops are a 422; an already-connected pair is a 409 unless allow_duplicate: true. label free text, line_style solid|dashed|dotted, style the look (colour, width, arrowStart / arrowEnd: none|arrow|open|diamond|circle, routing: straight|elbow|curved; anything else is dropped). A CMDB relationship only ever stands between two nodes.

🟠 PATCH .../connectors/{connector_id} Β  / Β  πŸ”΄ DELETE .../connectors/{connector_id}

PATCH updates label, line_style, style, cmdb_relationship_id (null clears, "auto" re-resolves; a 422 on a connector that ends on a shape).


πŸ“š Reference

🟒 GET /cmdb-icons Β  πŸ”‘ reference.read

The icon catalogue β€” every icon_key usable as a class icon or a node's icon_override.


πŸ“Œ Notes & gotchas

  • Every node is a CI. Nodes must reference CMDB objects. If discovery finds something new, create the CI first (via the CMDB API), then draw it - the diagram's boxes are always backed by real inventory. Freestanding shapes (zones, labels, an Internet cloud) are not CIs; they are read and written as the shapes list of a full-replace PATCH.
  • Strict where the editor is lenient: unknown object ids, sizes, icon keys and line styles are 422s (the editor silently skips bad rows on save).
  • Deleting a CMDB object removes it from every diagram β€” nodes and their connectors go with the CI (as of the #705 integrity fix; previously grown installs silently dropped the boxes from view while leaving orphaned rows behind).
  • The PNG/PDF export is client-side (rendered in the browser), so the API can't produce images β€” only the structure. Render pipelines can consume the hydrated GET instead.
  • Coordinates are canvas pixels, top-left origin; layout.node_sizes_px gives each size class's footprint so an agent can reason about overlap and spacing.

See also: REST API (how it all works) Β· REST API: CMDB (the objects behind the nodes) Β· Network Mapper (the module itself) Β· the other module guides linked from the sidebar.