API Logs Download Script Using Python (Assistance Request)
To start, I feel like there should be an answer to this issue somewhere by now but I failed to find any existing issues in any other chat discussions. If this one is already answered somewhere please point me in that direction!
I'm attempting to use Python to make API requests and download logs for a specific profile. The script I've written is very simple but I'm getting a {"errors":[{"code":"notFound"}]} error, which I have not been able to figure out as of yet.
Below is the script I'm using (with <variable> in place of the actual data I'm using in my script):
import requests
url = "https://api.nextdns.io/profiles/<profile>/logs/download?from=-1d&to=now&limit=10"
headers = {'X-Api-Key': '<api-key>'}
response = requests.get(url, headers=headers)
print(response.text)
Does anyone have any pointers on what I'm doing wrong?
2 replies
-
I'm not able to pass any query parameters without getting:
Error occurred while downloading logs: 400, {"errors":[{"code":"extraneous","source":{"parameter":"from"}},{"code":"extraneous","source":{"parameter":"to"}},{"code":"extraneous","source":{"parameter":"limit"}}]}
Though I'm able to download the entire log with this:
import requests import sys def download_logs(profile_id, api_key): url = f"https://api.nextdns.io/profiles/{profile_id}/logs/download" headers = {'X-Api-Key': api_key} response = requests.get(url, headers=headers) if response.status_code == 200: with open('logs.csv', 'wb') as file: file.write(response.content) print("Logs downloaded successfully.") else: print(f"Error occurred while downloading logs: {response.status_code}, {response.text}") if __name__ == "__main__": if len(sys.argv) != 3: print("Usage: python logs.py <profile_id> <api_key>") else: profile_id = sys.argv[1] api_key = sys.argv[2] download_logs(profile_id, api_key)
-
you need to use the config id and not the name of the profile
this solved the problem for me
Content aside
- 1 yr agoLast active
- 2Replies
- 196Views
-
3
Following