netLD API HowTo
This example shows the basic netLD API flow: authenticate with an API key, send a JSON-RPC request to
Inventory.search, and print the returned devices. Each language uses a small
netld_example_client helper so the search script stays readable.
requests and python-dotenv packagesdotenv packageDefault.env File
Keep credentials out of source code. Put the API URL, API key, network, and search parameters in a local
.env file that is not committed to source control.
NETLD_BASE_URL="https://netld.example.com"
NETLD_API_KEY="replace-with-your-api-key"
NETLD_NETWORK="Default"
NETLD_SEARCH_SCHEME="ipAddress"
NETLD_SEARCH_QUERY="10.95.1.0/24"
Example helper
These examples include a small netld_example_client helper to handle login, sessions, JSON-RPC
formatting, redirects, and errors. It is example code, not a supported SDK package. Use it as a starting point,
then adapt it to your team’s automation standards.
Download the example bundle for your language. Each bundle includes the short search script, the matching example
client, and a .env.example template. The search script is the part you edit for different searches.
import os
from netld_example_client import NetLDClient, print_devices
client = NetLDClient.from_env()
client.login()
page_data = client.search_inventory(
networks=[os.environ.get("NETLD_NETWORK", "Default")],
schemes=os.environ.get("NETLD_SEARCH_SCHEME", "ipAddress"),
queries=os.environ.get("NETLD_SEARCH_QUERY", "10.95.1.0/24"),
)
print_devices(page_data)
python -m pip install requests python-dotenv
python search_inventory.py
import "dotenv/config";
import { NetLDClient, printDevices } from "./netld-example-client.mjs";
const client = NetLDClient.fromEnv();
await client.login();
const pageData = await client.searchInventory({
networks: [process.env.NETLD_NETWORK || "Default"],
schemes: process.env.NETLD_SEARCH_SCHEME || "ipAddress",
queries: process.env.NETLD_SEARCH_QUERY || "10.95.1.0/24",
});
printDevices(pageData);
npm install dotenv
node search-inventory.mjs
param(
[string]$EnvPath = "$PSScriptRoot/.env"
)
. "$PSScriptRoot/NetLDExampleClient.ps1"
Import-DotEnv -Path $EnvPath
$baseUrl = $env:NETLD_BASE_URL
$apiKey = $env:NETLD_API_KEY
$network = if ($env:NETLD_NETWORK) { $env:NETLD_NETWORK } else { "Default" }
$searchScheme = if ($env:NETLD_SEARCH_SCHEME) { $env:NETLD_SEARCH_SCHEME } else { "ipAddress" }
$searchQuery = if ($env:NETLD_SEARCH_QUERY) { $env:NETLD_SEARCH_QUERY } else { "10.95.1.0/24" }
$debugMode = $env:NETLD_DEBUG -eq "1"
if (-not $baseUrl) {
throw [NetLDError]::new("Set NETLD_BASE_URL in .env before running this example.")
}
if (-not $apiKey) {
throw [NetLDError]::new("Set NETLD_API_KEY before running this example.")
}
$client = [NetLDClient]::new($baseUrl, $apiKey, 10, $debugMode)
$client.Login()
$pageData = $client.SearchInventory(
@($network),
@($searchScheme),
@($searchQuery),
0,
100,
"ipAddress",
$false
)
Show-Devices -PageData $pageData
pwsh -File ./search-inventory.ps1
Login status=200
Returned 3 of 3 matching devices
10.95.1.12 core-switch-01 Cisco::IOS
10.95.1.13 core-switch-02 Cisco::IOS
10.95.1.44 branch-fw-01 PaloAlto::PANOS
Change the search scheme and query to search by a different supported inventory field.
NETLD_SEARCH_SCHEME="hostname"
NETLD_SEARCH_QUERY="core-switch"
Common Gotchas
Inventory.search expects search text with a trailing newline.network parameter is passed as a list, even for one network.NETLD_DEBUG=1 to print JSON-RPC request and response payloads.
Understand, monitor, and control your network with ThirdEye, free for 30 days.