config.py

# Add this file to your .gitignore to prevent it from being committed to version control
ACCESS_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

 

api_url = ‘https://xxxxxxxxxxxxxxxxxxxxxxxxxxx/api/v2/monitor/system/config/backup’

api_backup.py

import requests
from pprint import pprint
import config


# Define the base URL without the access token
url = config.api_url
key = config.ACCESS_TOKEN

# Define the URL parameters
params = {
'scope': 'global'
}

# Define the headers, including the Authorization header with the Bearer token
headers = {
'Authorization': f'Bearer {key}'
}
response = requests.get(url, params=params, headers=headers, verify=True)
results = response.text
pprint(results)

'''
('#config-version=FGT61F-7.2.12-FW-build1761-250909:opmode=0:vdom=0:user=NetAdmin_API\n'
This line will not write in json to a file.
'''




I put the API key and url in the config.py.  This is used in all the API projects.   

('#config-version=FGT61F-7.2.12-FW-build1761-250909:opmode=0:vdom=0:user=NetAdmin_API\n'

This line will not write in json to a file.