The fileRetrieve API call is used to download files from your company's root folder.
This is only possible if the user has approved your access.
(see Listing Accounts and Account Details)
{
"action": "fileRetrieve",
"uid": 1001,
"squid_id": "64"
}
Success:
{
"error": "",
"status": "success",
"data": "-- Base64 encoded AES-256-CBC encrypted JSON --",
"action": "fileRetrieve",
"version": "1.07",
"proc_time": 1651419658,
"proc_id": 77
}
"data" (decrypted)
{
"filename": "sample1.xlsx",
"content": "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,UEsDBBQABgAIA...RU5ErkJggg=="
}
filename: The current filename that the user has set in the vault.
content: the actual file content as a base64 data URL. i.e.
data:[mime-type];base64,[base64 encoded file]
Failure:
{
"error": "invalid squid_id",
"status": "failure",
"data": "-- Base64 encoded AES-256-CBC encrypted JSON --",
"action": "fileRetrieve",
"version": "1.07",
"proc_time": 1651425411,
"proc_id": 77
}
"data" (decrypted)
{}
no uid: uid missing
invalid uid: account uid unauthorised or invalid
not approved: The the user hasn't approved your access.
no squid_id: squid_id empty or missing
invalid squid_id: squid_id unauthorised or invalid
We suggest that you either perform a fileCreate or fileListing to obtain a valid reachable squid_id.
<?php
$responseArray = request([
'action'=>'fileRetrieve',
'uid'=>1001,
'squid_id'=>'18'
]);
$fileArray = json_decode($responseArray['data'],true);
list(, $fileArray['content']) = explode(';', $fileArray['content']);
list(, $fileArray['content']) = explode(',', $fileArray['content']);
$filesize = file_put_contents('/tmp/'.$fileArray['filename'], base64_decode($fileArray['content']));
if($filesize>0){
echo 'write successful : ';
print_r($fileArray);
}else{
echo 'write failed';
}
?>
Copy Code