I am trying to get all the information such as name, content of the file downloaded when I hit a GET API programmatically.
Context :
I have a GET API, whenever I hit that API from browser it automatically downloads the file into the system, I can see that file in filesystem. I would like achieve this using Python program.
Tested Approach :
I almost tried every approach to get the contents of the file, every time I download the file content appears to be in JavaScript format instead of text.
Python Code :
caseDocumentFolderPath = os.path.join(SubpoenaJobpath,caseDocumentsFolderName)
os.chdir(caseDocumentFolderPath)
documentResponse = requests.post(completeZipDownloadUrl, headers=headers)
print(documentResponse.content)
open('temp.txt', 'wb').write(documentResponse.content)
Output file :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<script>
function redirectOnLoad() {
if (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('https://texastech.my.salesforce.com?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Ftexastech.lightning.force.com%252Fcontent%252Fsession%253Furl%253Dhttps%25253A%25252F%25252Ftexastech.file.force.com%25252Fsfc%25252Fservlet.shepherd%25252Fdocument%25252Fdownload%25252F0696T00000OcugCQAR%25253FoperationContext%25253DS1'); } else
if (window.location.replace){
window.location.replace('https://texastech.my.salesforce.com?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Ftexastech.lightning.force.com%252Fcontent%252Fsession%253Furl%253Dhttps%25253A%25252F%25252Ftexastech.file.force.com%25252Fsfc%25252Fservlet.shepherd%25252Fdocument%25252Fdownload%25252F0696T00000OcugCQAR%25253FoperationContext%25253DS1');
} else {
window.location.href ='https://texastech.my.salesforce.com?ec=302&startURL=%2Fvisualforce%2Fsession%3Furl%3Dhttps%253A%252F%252Ftexastech.lightning.force.com%252Fcontent%252Fsession%253Furl%253Dhttps%25253A%25252F%25252Ftexastech.file.force.com%25252Fsfc%25252Fservlet.shepherd%25252Fdocument%25252Fdownload%25252F0696T00000OcugCQAR%25253FoperationContext%25253DS1';
}
}
redirectOnLoad();
</script>
</head>
</html>
Note: The link which allows the file download directly to browser is from Salesforce and I have tested the link is working fine. Here is the proof for that: