I am trying to download the provisioning report after I make the post api call. Except when I use requests or urllib.request.urlretrieve and any other means to open the file url. the response is meta data about the provisioning report I am trying to download rather than the actual provioning report. help
Did you wait for the provisioning report to finish and then use the URL supplied? When you make the POST, it starts the process of generating the report and gives you a progress report until it's done. Check the status of the report to see if it's ready for download.
Once the report status is "complete" and the progress is "100", then there should be an URL that you can use.
The first one says file_url, for example, the pathname may be "/accounts/1234/files/109772350/download"
That is not an API call and you have to be logged into Canvas to use it. Adding the Authorization header won't help since you're not using the API.
There is also an attachment object that has a URL. This URL with have a query string with a download_frd=1 and a verifier code on it. The verifier code is what allows you to access it without being logged into Canvas.
You have undoubtedly seen the Accounts Report API documentation or you wouldn't be as far as you are (unless you're trying to fix someone else's code), but I link it here for other people who may stumble across this question.
Here's my Python code for requesting and downloading the provisioning report. It's specific to my environment so you'd need to tweak it for yours:
report_id = api.post(f"accounts/{account_id}/reports/provisioning_csv", req_data).json()['id']
progress = 0
while progress < 100:
sleep(5)
response = api.get(f"accounts/{account_id}/reports/provisioning_csv/{report_id}")
json = response.json()
progress = json['progress']
content = api.get(json['attachment']['url'], stream=True).content
with open(config.output_dir + json['attachment']['filename'], 'wb') as file:
file.write(content)
This was helpful! I was trying to use the first file_url to download but just switching to the actual download url did it! Thanks!
It is important to know that because you need to modify the program accordingly to the structure of your report in case you want to save it as a CSV file.
Get the results of a provisioning report in an external application with a Python CSV script.
The result can also be saved as a JSON or CSV file.
When you make the POST, it starts the process of generating the report and gives you a progress report until it's done. Check the status of the report to see if it's ready for download.
For example, your post request looks like below.
POST /api/v1/accounts/:account_id/reports/:report
So, this is how you download the provisioning_csv with Python.
I hope it helps.