API "api/dcim/devices/" can't get all devices #2548

Closed
opened 2025-12-29 18:19:52 +01:00 by adam · 2 comments
Owner

Originally created by @guyue77 on GitHub (Apr 25, 2019).

Hello,

Environment

  • Python version: 3.7.2
  • NetBox version: 2.5.8

Steps to Reproduce

  1. GET /api/dcim/devices/ #results as below:
    HTTP 200 OK
    Allow: GET, POST, HEAD, OPTIONS
    Content-Type: application/json
    Vary: Accept

{
"count": 65,
"next": "http://10.10.121.249/api/dcim/devices/?limit=50&offset=50",
"previous": null,
"results": [
{

  1. Check the results ,count is 65 ,but only list the first 50 item,miss the last 15.

I want to get the all device ID through the API ,but I can't cmplete it.

Originally created by @guyue77 on GitHub (Apr 25, 2019). Hello, ### Environment * Python version: 3.7.2 * NetBox version: 2.5.8 ### Steps to Reproduce 1. GET /api/dcim/devices/ #results as below: HTTP 200 OK Allow: GET, POST, HEAD, OPTIONS Content-Type: application/json Vary: Accept { "count": 65, "next": "http://10.10.121.249/api/dcim/devices/?limit=50&offset=50", "previous": null, "results": [ { 2. Check the results ,count is 65 ,but only list the first 50 item,miss the last 15. I want to get the all device ID through the API ,but I can't cmplete it.
adam closed this issue 2025-12-29 18:19:52 +01:00
Author
Owner

@Grokzen commented on GitHub (Apr 25, 2019):

The default pagesize for the API is 50 and defined by this setting https://github.com/digitalocean/netbox/blob/develop/netbox/netbox/settings.py#L66 so if you want a bigger pagesize for your API then you need to increase that value. However, you should note that having an infinite pagesize that would always return all the items is bad practise so you should already built into your application that it will follow the attribute next that is outputed in the API. If that field is set in your response, it means that you have more values on the next page to parse and your API consumer code should query that as well until you have consumed all pages from your API and then merge the data from all pages into your deisred response. If you are using pynetbox api client, it will do this automatically for you.

In the case you know you have a very small dataset, you can increase the pagesize to something like 1000 items through the settings and in a way assume that you will always get back everything.

One more small tip is that if you are only interested in the ID/name/slug for any item in the API, consider using the ?brief=1 GET url paramter to remove basically all data except the ID/name/slug from your response. This will increae the API response time and reduce the database load for your query.

@Grokzen commented on GitHub (Apr 25, 2019): The default pagesize for the API is 50 and defined by this setting https://github.com/digitalocean/netbox/blob/develop/netbox/netbox/settings.py#L66 so if you want a bigger pagesize for your API then you need to increase that value. However, you should note that having an infinite pagesize that would always return all the items is bad practise so you should already built into your application that it will follow the attribute `next` that is outputed in the API. If that field is set in your response, it means that you have more values on the next page to parse and your API consumer code should query that as well until you have consumed all pages from your API and then merge the data from all pages into your deisred response. If you are using pynetbox api client, it will do this automatically for you. In the case you know you have a very small dataset, you can increase the pagesize to something like 1000 items through the settings and in a way assume that you will always get back everything. One more small tip is that if you are only interested in the ID/name/slug for any item in the API, consider using the `?brief=1` GET url paramter to remove basically all data except the ID/name/slug from your response. This will increae the API response time and reduce the database load for your query.
Author
Owner

@jeremystretch commented on GitHub (Apr 25, 2019):

This is all explained in the documentation.

@jeremystretch commented on GitHub (Apr 25, 2019): This is all explained in [the documentation](https://netbox.readthedocs.io/en/stable/api/overview/#pagination).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2548