How to download csv of an API submitted job

While submit a sql via UI then there will be a link available to download result csv as below:
http://server_ip:9047/apiv2/job/job_id/download
Python open(“test.csv”, “wb”) as f and f.write(response.content) can really save it as csv.
However, if a sql submitted by API, request to http://server_ip:9047/apiv2/job/job_id/download will say 404 not found:
{
“errorMessage”: “Something went wrong”,
“moreInfo”: “Job JobId{id=job_id, name=null} has no data that can not be downloaded, invalid type REST at [/job/job_id] not found”
}

I just want to download the result csv of a job, unfortunately there is no API found in docs so I tried and found that link in UI after click csv button. How can I do that please?

Hi,

We currently do not have a documented API to do CSV downloads - the UI uses a internal API that may change at any time. The download actually uses websockets to monitor the progress of the job before initiating the file download since queries can run for a while.

You best choice right now is to use the SQL API to run the query and then fetch the results using the Job API. The results will be JSON so you would have to convert them to CSV in whatever language you are working with.