Home > Forum > Actions > Download Excel file from external REST API

Download Excel file from external REST API
0

Hi all!

We are using the action 'Invoke REST Web service' a lot, but there are some limitations I am struggling with.

I want to download an Excel file using this action, using an external REST service.

My first approach was to store the response body into a multi-line content field. I am also using a HTML field with a download button, to save this file from content field to disk.

This method is working very good with plain/text.

After saving file from Content field to disk, Excel is corrupt.

I think this has something to do with content-type or encoding, but I can't figure out, how to get the raw content.

Is there even a way to do this with standard action or do we have to implement a SDK action for this (e.g. call REST service and add file as an attachment).

Would be nice, if anyone could point me into the right direction.

Thanks a lot in advance, Nik

MVP
In reply to: Nikolaus Schusser

Hi Maksymilian!

Thanks for your answer.

I ended up with Powershell (Invoke-WebRequest) and a SDK action, which fetches the downloaded file from filesystem and adds it as attachment.

Works like a charm and was much faster than experimenting with the standard action ;-)

Best regards, Nik

That's an interesting idea Nik. It will probably be easier to handle any issue with the request using the PS script.
I'm guessing that you pass the filename to the PS script so that you can retrieve the correct file for this workflow instance using the SDK action. Or you are passing the instance id and the PS script stores the file in a folder?

Do you clean up the folder from within the SDK or is this handled by another PS script.
I haven't touched the filesystem with an SDK so I'm curious. :)

Best regards,
Daniel

In reply to: Daniel Krüger (Cosmo Consult)

That's an interesting idea Nik. It will probably be easier to handle any issue with the request using the PS script.
I'm guessing that you pass the filename to the PS script so that you can retrieve the correct file for this workflow instance using the SDK action. Or you are passing the instance id and the PS script stores the file in a folder?

Do you clean up the folder from within the SDK or is this handled by another PS script.
I haven't touched the filesystem with an SDK so I'm curious. :)

Best regards,
Daniel

Hi Daniel!

Powershell looks something like this:

$user = '{EGV:63}'
$pass = '{EGV:64}'

$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"

$Headers = @{
Authorization = $basicAuthValue
}

Invoke-WebRequest -Uri {EGV:1}/rest{I:2821} -Headers $Headers -OutFile "C:\Temp\{N:2821}.xlsx" -UseBasicParsing

Note that filename and endpoint are controlled by a dropdown in form, since there are several reports to generate. SDK grabs this file from filesystem and adds it as attachment. Attachment Id will be stored in a form field, to provide a preview link. SDK does not clean up this file, but this is a good idea, I will add this option to SDK action configuration.

Note that we have full control over the environment (e.g. file system permissions) since this is a On-Premise installation. This would not work in a SaaS environment.

Best regards, Nik