REST call for file download

I was wondering what the recommended way to use a KNIME Server workflow to return a file is. Currently I need to do this with KS 4.2.

So far I found @RolandBurger’s nice Upload/Download workflow.

But then I think I need to first :execute, parse the response and then construct the download URL.

Is there a slicker way to do this with one REST call? If not in 4.2, is it possible in a newer version?

One more thing I noticed in KS 4.2. In the Swagger UI I couldn’t put slashes into workflow paths when testing REST calls. The workaround was to move my workflow to the repository root. Is that an already known issue? Is it fixed already in a newer version?

Hi Jon,

unfortunately I don’t think this is possible at the moment. A workflow job can create an outputResources field which lists all available resources the job has created. This can of course also be dynamic if for example container nodes where configured with flow variables or part of active/inactive branches in the workflow. This field is listed wherever a job is returned in a REST response. This could be in the regular jobs/{uuid} get endpoint and also in the :execution endpoint.
The only call to download a generated output resource is then jobs/{uuid}/output-resources/{resourceId} where you need to provide both the job id and the resource id from a previously parsed response.

Hope you’re doing well!
Cheers,

Christian

1 Like

Thanks for the answer @albrecht , today is a good day :wink:

We can work with the suggested solution. Would be great if in future it were possible to do it with :execute and perhaps a dedicated container node.

Could someone comment on the second point regarding the Swagger UI and paths to workflows deeper in the repository?

Hi Jon,

Seems it is your lucky day: We’re about to release AP 4.4, which comes with two new nodes:

Maybe this helps with your use case?

I’ll look into the swagger issue and keep you updated.

Cheers,
Roland

1 Like

Hi @jonfuller

Sorry for the late reply!

This is something we also recently realized and this seems to be a bug in swagger. We don’t have an update for this yet.

However, you can access /rest/v4/repository/{path/to/workflow}:openapi to get tests that already have the path baked in, where the path will not falsely be encoded (this is also the link that is opened, if you right click a server workflow in an Analytics Platform and select “Show API Definition”).

Kind regards
Marvin

Hi @RolandBurger ,

I tried to expose a .csv to the REST Api:

image

When trying to access it via a GET (https://…/Excel_Download:execution) request, I only get metadata information, which looks like this:

{
“id”: “…”,
“discardAfterSuccessfulExec”: false,
“discardAfterFailedExec”: false,


],
“executorID”: “…”,
“createdVia”: “Webportal”,
“owner”: “…”,
“state”: “EXECUTION_FINISHED”,
“name”: “Excel_Download 2022-04-08 16.13.19”,
“properties”: {
“com.knime.enterprise.server.executor.requirements”: “”,
“com.knime.enterprise.server.jobpool.size”: “0”
},
“isOutdated”: false,
“createdAt”: “2022-04-08T16:13:19.418698Z[UTC]”,
“startedExecutionAt”: “2022-04-08T18:13:05.532934Z[Etc/UTC]”,
“notifications”: {},
“finishedExecutionAt”: “2022-04-08T16:13:19.583936Z[UTC]”,
“workflow”: “…/Excel_Download”,
“hasReport”: false,
“isSwapped”: false,
"outputResources": {
“download-csv”: "extract_workflow_data_area"

}
}

How can I now retreive now the csv. It is mentioned as “output resources”, as far as I can tell, yet I was not able to generate the download. Help would be very much appreciated :slight_smile:

Best,
Stiefel

Hi folks,

Solved my issue.
Triggering a file download needs to first execute the REST call via:
REQUEST_URL:jobs
and not
REQUEST_URL:execute
The latter discards the job.

Once this query is executed correctly, it generates a request ID, which then can be used for a file download.

The specified parameter name from the output node needs to be referenced:

Eventually the query looks like this:

{knime_server_endpoint}/knime/rest/v4/jobs/{request_ID}/output-resources/{download-csv}?timeout={30000}

Cheers,
Stiefel

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.