I am trying to use an API (notably the companieshouse one) and have managed to get it working to the point where I can use the command line to make a request to the API website and have data returned, I do this using the following code:
r = requests.get('https://api.companieshouse.gov.uk/company/**COMPANY NUMBER**/filing-history', auth=('**AUTH CODE**', ''))
You can make a string out of your JSON like this:
import json json_str = json.dumps(r.json())
And then save it as a regular text file using standard methods.
with open(filename, 'w') as f: f.write(json_str)