Functions/Get-SlackFile.ps1
<#
.SYNOPSIS This function gets files from a Slack team. .DESCRIPTION This function gets files from a Slack team. The scope required to call this function is "files:read". #> function Get-SlackFile { [CmdletBinding(PositionalBinding=$false)] [OutputType([PSObject])] param( # The authentication token for Slack [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [String]$token ) # Prepare the API call parameters $invokeRestMethodParams = @{ Uri = "https://slack.com/api/files.list" Method = "GET" Headers = @{ "Content-Type" = "application/x-www-form-urlencoded" Authorization = "Bearer $($token)" } } # Invoke the call $response = Invoke-RestMethod @invokeRestMethodParams # Verify that the retrieval is successful if ($response.ok) { return $response.files } else { throw "Failed to get files with the error message:`r`n$($response.error)." } } |