Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit bd9274a

Browse files
committed
add all list endpoint
1 parent 0256492 commit bd9274a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

netbox_python/baseapi.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ class ListableAPIResource:
2020
def list(self, **kwargs):
2121
return self.client.get(self.path, params=kwargs)
2222

23+
def all(self, **kwargs):
24+
ret = self.client.get(self.path, params=kwargs)
25+
pagination = ret.pagination
26+
while pagination["next"]:
27+
partial = self.client.get(
28+
self.path, url_override=pagination["next"], params=kwargs
29+
)
30+
ret.data.append(partial.data)
31+
pagination = partial.pagination
32+
33+
ret.pagination["next"] = None
34+
ret.pagination["previous"] = None
35+
return ret
36+
2337

2438
class RetrievableAPIResource:
2539
def get(self, id):

netbox_python/rest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(
2929
self.headers = headers
3030
self.message = str(message)
3131
self.data = data if data else []
32+
self.pagination = pagination
3233

3334

3435
class RestClient:
@@ -49,10 +50,13 @@ def close(self):
4950
return self._session.close()
5051

5152
def request(self, method: str, path: str, **kwargs) -> JSONType:
52-
path = f"{self.base_url}/{path}"
53+
url = kwargs.pop("url_override", None)
54+
if not url:
55+
url = f"{self.base_url}/{path}"
56+
5357
data_out = None
5458
try:
55-
response = self._session.request(method=method, url=path, **kwargs)
59+
response = self._session.request(method=method, url=url, **kwargs)
5660
response.raise_for_status()
5761
except requests.HTTPError as http_error:
5862
raise NetBoxException(

0 commit comments

Comments
 (0)