The API can be used to perform most functions available in the GUI. To perform complex queries of data in the API, it is necessary to insert an NQE query into the API call, or reference an existing NQE query in the Repository.
In this example, we first create an NQE query in the Org Repository called list-interfaces. This NQE query will iterate through each device, interface, and sub-interface and list the IP addresses and MAC addresses for each interface.
foreach device in network.devices
foreach interface in device.interfaces
foreach subinterface in interface.subinterfaces
let ipv4 = subinterface.ipv4
foreach address in ipv4.addresses
select {
deviceName: device.name,
interfaceName: interface.name,
subinterfaceName: subinterface.name,
ip: ipSubnet(address.ip, address.prefixLength),
macAddress: interface.ethernet.macAddress
}
The output of the NQE in the GUI looks like this:
![](https://uploads-us-west-2.insided.com/forwardnetworks-us/attachment/e65677bb-70fe-4304-b3be-13369ec8382e.png)
In order to access this information via the API, you must first commit the query. Then get the Query ID and the Commit ID by clicking on the (i) next to the query name.
![](https://uploads-us-west-2.insided.com/forwardnetworks-us/attachment/59820938-12c2-4d6d-b2a1-035573efee7d.png)
You will the need the Query ID, the commit ID, the Network ID, and the Snapshot ID to include in the API call. (The Network ID and Snapshot ID are in the URL when you are working in a given Network and Snapshot).
The `commitId` is only required if you want to reference a previous commit or the query was deleted from the library.
The following API call will pull data for the NQE Query using a POST operation. The output is sorted by ascending device names and filtered based on device names that include “ATL”. (Note that case for “ATL” is ignored)
curl -X 'POST' \
'https://fwd.app/api/nqe?networkId=153030&snapshotId=514184' \
-H 'accept: application/json' \
-H 'Authorization: Basic << REDACTED >>' \
-H 'Content-Type: application/json' \
-d '{
"queryId": "Q_044a4fe380c1c9baf0bd91fc367f67ca29450088",
"commitId": "b1a1ddbeb2460bff6653af32a4b0517ff6f318c7",
"queryOptions": {
"offset": 20,
"limit": 100,
"sortBy": {
"columnName": "deviceName",
"order": "ASC"
},
"columnFilters": n
{
"columnName": "deviceName",
"value": "ATL"
}
]
}
}'
The output from this API call will be formatted in JSON
{
"snapshotId": "514184",
"items":
{
"deviceName": "atl-ce01",
"interfaceName": "ge-0/0/8",
"subinterfaceName": "ge-0/0/8.107",
"ip": "10.110.2.184/31",
"macAddress": "00:03:00:00:00:0c"
},
{
"deviceName": "atl-ce01",
"interfaceName": "ge-0/0/8",
"subinterfaceName": "ge-0/0/8.108",
"ip": "10.110.2.180/31",
"macAddress": "00:03:00:00:00:0c"
},
{
"deviceName": "atl-ce01",
"interfaceName": "ge-0/0/9",
"subinterfaceName": "ge-0/0/9.103",
"ip": "10.10.2.21/31",
"macAddress": "00:03:00:00:00:0d"
},
...
More details about how to use the NQE API can be found here: https://fwd.app/api-doc#nqe