Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
I am trying to figure out a way to be able to download the log file using the REST API.
I able to locate the file using the API endpoint FileReference. However, i am not able to figure out a way to be able to download the file as a result of the API call.
here is what i am using
REST call: <servername>/qrs/filereference/<filereference_id>
Response:
id : fd8ad364-109b-4924-adfa-7ae285bbf00d createdDate : 2019-03-05T10:38:35.354Z modifiedDate : 2019-03-05T10:38:35.354Z modifiedByUserName : INTERNAL\sa_scheduler location : myserver\Script\40ab5878-2164-4275-bbe0-0824fa04e040.2019_03_05_10_19_11.B5B796AD93CF2FFCEC06.log size : 309341 hash : flG4jmMasEaHO7OJiV9Nxbw== syncDirection : 1 fileType : 1 privileges : schemaPath : FileReference
As you can see, i have the log file name and the path under the location key.
Can someone help me figure out how to download the file.
Thanks,
Aadil
Hello,
If interested, this is some Qlik Sense script code to download the log file and save it locally.
It is assuming you have a working REST data connection to QRS API named 'QRS API'
and it uses both
https://localhost/qrs/ReloadTask/$(sTaskId)/scriptlog
https://localhost/qrs/download/reloadtask/$(vFileReferenceID)/<tmp file>
repository API
We are using it to retrieve regularly the logs of failed jobs before they get overwritten by latest reload task and to fill a Qlik application to track job execution
Thomas
// -------------- GetLog --------------------
// Download a task log file via QRS API
// - Save it locally as log file named sLogName
sub TaskLogs.GetLog(sLogName,sTaskId,sReferenceId)
TRACE *** Retrieving log ""$(sLogName)"" from taskID $(sTaskId)], referenceId $(sReferenceId);
// Parameters for QRS API calls
set vlQRSAPIXrfkey='adcdef0123456789';
set ErrorMode=0;
TRACE *** Starting qrs/ReloadTask import;
// Get the "operational"."fileReferenceID"
// see https://community.qlik.com/t5/Qlik-Sense-Integration/Download-LOG-file-using-QRS-API/m-p/1567020#M10312
LIB CONNECT TO 'QRS API';
RestConnectorMasterTable:
SQL SELECT
"value"
FROM JSON (wrap on) "root"
WITH CONNECTION (
URL "https://localhost/qrs/ReloadTask/$(sTaskId)/scriptlog",
QUERY "fileReferenceId" "$(sReferenceId)",
QUERY "Xrfkey" "$(vlQRSAPIXrfkey)",
HTTPHEADER "X-Qlik-Xrfkey" "$(vlQRSAPIXrfkey)",
HTTPHEADER "User-Agent" "Windows"
);
// Verify the validity of the RestConnectorMasterTable
if IsNull(TableNumber('RestConnectorMasterTable')) or NoOfRows('RestConnectorMasterTable')=0 then
TRACE *** ERROR: Failure when calling QRS API with ReloadTask/$(sTaskId)/scriptlog...;
else
[root]:
LOAD [value]
RESIDENT RestConnectorMasterTable;
DROP TABLE RestConnectorMasterTable;
let vFileReferenceID=Peek('value',0,'root');
TRACE *** TaskLogs.Add retrieved vFileReferenceID $(vFileReferenceID);
DROP TABLE root;
end if;
// Get the file and save it
// As this is not true CSV, we need to use a improbable delimiter like 'µ'
// This is working unless you are trying to get a log which contains this
// particular character
// if you have a better idea please let me know...
RestConnectorMasterTable:
SQL SELECT
"col_1"
FROM CSV (header off, delimiter "µ", quote """" ) "TaskLogs"
WITH CONNECTION (
URL "https://localhost/qrs/download/reloadtask/$(vFileReferenceID)/tmp.log",
QUERY "Xrfkey" "$(vlQRSAPIXrfkey)",
HTTPHEADER "X-Qlik-Xrfkey" "$(vlQRSAPIXrfkey)",
HTTPHEADER "User-Agent" "Windows"
);
// Verify the validity of the RestConnectorMasterTable
if IsNull(TableNumber('RestConnectorMasterTable')) or NoOfRows('RestConnectorMasterTable')=0 then
TRACE *** ERROR: Failure when calling QRS API with download/reloadtask/$(vFileReferenceID)/tmp.log...;
else
[Log]:
LOAD "col_1" as "line"
RESIDENT RestConnectorMasterTable;
DROP TABLE RestConnectorMasterTable;
if ( NoOfRows('Log') > 1 ) then
STORE "Log" INTO [$(sLogName)] (txt);
end if;
DROP TABLE [Log];
end if;
set vFileReferenceID=;
set vlQRSAPIXrfkey=;
set ErrorMode=1;
end sub;
Thanks. This is cool.
Thanks a lot. I did all you said, but getting a 404 response. Can you please help in this regard?