Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions examples/zone-export-json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Copyright (c) 2026 NSONE, Inc.
#
# License under The MIT License (MIT). See LICENSE in project root.
#

import os
import sys
import json

from ns1 import NS1, Config

zone_name = sys.argv[1]
env_api_key = os.environ.get("NS1_API_KEY", None)

if env_api_key:
api_key = env_api_key
ns1_config = Config()
ns1_config.createFromAPIKey(api_key)
api = NS1(config=ns1_config)
else:
# NS1 will use config in ~/.nsone by default
api = NS1()

# turn on "follow pagination". This will handle paginated responses for
# zone list and the records for a zone retrieve. It's off by default to
# avoid a breaking change
config = api.config
config["follow_pagination"] = True

zone = api.zones().retrieve(zone_name, params={"export": True})
print(json.dumps(zone, indent=2, sort_keys=True))
6 changes: 5 additions & 1 deletion ns1/rest/zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@ def list(self, callback=None, errback=None):
pagination_handler=zone_list_pagination,
)

def retrieve(self, zone, callback=None, errback=None):
def retrieve(self, zone, callback=None, errback=None, params=None):
kwargs = {}
if params is not None:
kwargs["params"] = params
return self._make_request(
"GET",
"%s/%s" % (self.ROOT, zone),
callback=callback,
errback=errback,
pagination_handler=zone_retrieve_pagination,
**kwargs,
)

def search(
Expand Down
10 changes: 6 additions & 4 deletions ns1/zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ def __repr__(self):
def __getitem__(self, item):
return self.data.get(item, None)

def reload(self, callback=None, errback=None):
def reload(self, callback=None, errback=None, params=None):
"""
Reload zone data from the API.
"""
return self.load(reload=True, callback=callback, errback=errback)
return self.load(
reload=True, callback=callback, errback=errback, params=params
)

def load(self, callback=None, errback=None, reload=False):
def load(self, callback=None, errback=None, reload=False, params=None):
"""
Load zone data from the API.
"""
Expand All @@ -60,7 +62,7 @@ def success(result, *args):
return self

return self._rest.retrieve(
self.zone, callback=success, errback=errback
self.zone, callback=success, errback=errback, params=params
)

def delete(self, callback=None, errback=None):
Expand Down
Loading