How can i collect below information from Forward Network via API for Network devices. ?
• IP address, • MAC address • Interface details • Device Name • Subnet details
1.Which API should be used to get the above information? In the documentation, I see an API to get networks/ Network collection/ devices ; 2.Is there a single API call that can pull the above information, or are there multiple API calls? 3.If it's one API call, what's the Max pagination limit? 4.Can you please provide a Sample API or a Postman export to make an API call.
Page 1 / 1
@Rohit_809 Kumar I don’t think there is a single published API that would provide this data. However, you can use NQE to essentially make “custom APIs”.
An NQE query can be accessed via a single API call /api/nqe. This is a POST, so there are options you can put into the body of the request. You would then write an NQE query that would list all the data that you want about a device. You could either run it as a non-parameterized query, where you do NOT pass in a device name. This would then give you this set of data for ALL devices covered in the NQE query. Or, you can use the parameterized NQE method to be able to pass in a single device name and get all this data back about that single device.
The NQE method does have a max limit of 10,000 lines in one response. There is a “offset” and “limit” to “page” through the results. The default limit is 1,000, but in the body of the post you can set the “limit” to 10,000.
If you are just returning the output for a single device then you are less likely to run into exceeding that 10,000 max limit.
Thanks @Tyson Henrie for the update ,
definetly we can write the NQE Query to get this data , but how can i colllect NQE Query data via API ?
Hello @Rohit_809 Kumar
As @Tyson Henrie mentioned you can execute NQE using our `/api/nqe` endpoint by using the queryId which can be found in the NQE Library:
Just a couple things to add on what Gary said. You need to “commit” your query before it is assigned a queryId. Then you can use the queryId in the body of the NQE API call (as shown in Gary’s example). The only additional bit you might need is the “limit”. An example “body” to the API would look like this:
I added the offset just for clarity in case you need to page through more than 10000 lines. Having “offset”: 0 should not cause any issues. This then show setting the “limit”: 10000. The default limit is 1000. That is mentioned in the swagger docs. Gary gave the url for those docs.
thanks @Tyson Henrie this is very helpful.
@Tyson Henrie and @GaryB can you please let us know ?.
we have approx 45000 values in NQE and from API , as mention the Limit is 10,000 , can you please let us know the offset and limit value for 40000 data ? and is their any issue on server end to collect too much data via api ?
Please let us know any their any Option to enable the Pagination value in API Response ?
Thanks
@Rohit_809 Kumar
The API already supports pagination when the # of records > limit. You simply need to wrap the call to NQE so that you can make multiple fetches based on the limit window.
Below as an example in Python but you could write this in any general purpose language.
# Note this is just an example, no guarantees, please make sure you understand what this code is doing before running.
except requests.exceptions.HTTPError as err: response_status = response.status_code if response_status in n401, 403]: print("Please set FWD_USER and FWD_PASSWORD to authentication credentials") elif response_status == 409: print("Snapshot is being processed, try again in a few") raise SystemExit(err)
except requests.exceptions.ConnectionError as err: print(f"Connection error occurred: {err}") break
return items
@GaryB what is the ideal value for offset and limt if we need to collect approx 40000 values vai API ?
@Rohit_809 Kumar As @Tyson Henrie mentioned and what is in our documentation, the maximum limit is 10,000.
So we increment the offset by 10,000 every round until there are no more items returned.
offset += limit
@Rohit_809 Kumar You need to “page” through the values.
first time - offset = 0, limit = 10000
second - offset = 10000, limit = 10000
third - offset = 20000, limit = 10000
forth - offset = 30000, limit = 10000
fifth - offset = 40000, limit = 10000
This is where you need to use a script with a loop. That is what @GaryB shared a couple posts ago. but this is to show you how the offset and limit work together to “page” through the results.