Skip to main content

Get Download Token Activity

Overview​

The Get Download Token (get_download_token) Activity will supports the image upload feature of a Pia form. You can refer to the image upload capabilities of the form builder here.

Using this activity, you can retrieve an image which has been uploaded using the camera (image upload) feature.

An example scenario where this activity is currently being used in Pia is the Upload Staff Photo package. The Get Download Token Activity is used to obtain a token which you can then use in your PowerShell script to download the image from Pia’s API.

The Get Download Token activity can be located by searching for "Get Download" in the list of activities in the package editor:

Get Download Token

Here is a working sample of the activity in a basic package:

# Pia Automation Package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Hello World'

- name: 'chat'
option_button: 'The name of the button in Pia'
option_text: 'Text which is displayed in the Pia Chatbot'
option_category: 'Pia Chatbot Category'

steps:
- task: chat_interaction
inputs:
text: 'Upload your image!'
form_name: 'upload_image_example'

- task: get_download_token
inputs:
data: =chat_interaction.form.image_to_upload

- task: inline_powershell
inputs:
piaTenantUrl: $Base_Url
downloadToken: =get_download_token.token
script: |
$WebClient = New-Object System.Net.WebClient
$bytes = $WebClient.DownloadData("$piaTenantUrl/Chat/Download?token=$downloadToken")

Write-Host "The image is $($bytes.count) bytes in size."

In the above example, the user submits a form with an image which can then be downloaded from Pia using the download token.

Activity Behaviour​

The primary behaviour of the Get Download Token activity is to allow you to download images from Pia which have been uploaded via a Pia form. The token generated by this activity is short lived and will expire in five minutes.

The Get Download Token Activity can be used in all package executions i.e. this activity will run for packages which have been initiated via the Pia Chatbot, via Schedule and via a Ticketing System Event.

Input Properties​

Use this property to modify the behaviour of the activity.

Property Name: data
Property Required: Yes
Property Description: The Id of the uploaded image as provided by the Pia form.

property_data

Output Properties​

There is a single property which the Get Download Token activity makes available:

Property Name: token
Property Description: A short lived token which can be used to obtain the image via the /Chat/Download?token=$downloadToken API endpoint. The token will expire in five minutes.