Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/greenlighttec/HaloAPI in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
greenlighttec committed Dec 11, 2023
2 parents 08e7bf5 + af5457a commit 1e048b7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions HaloAPI.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
'Get-HaloWorkflows',
'Import-HaloSuppliersFromAccountingPackage',
'Invoke-HaloRequest',
'Invoke-HaloSQL',
'New-HaloAction',
'New-HaloActionBatch',
'New-HaloAgent',
Expand Down
47 changes: 47 additions & 0 deletions Public/Invoke/Invoke-HaloSQL.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Function Invoke-HaloSQL {
<#
.SYNOPSIS
Uses the Reports API endpoint to run arbitrary SQL.
.DESCRIPTION
Function to run a report preview with a SQL query parameter. Use -IncludeFullReport to get the entire report object instead of just the results
.OUTPUTS
Outputs an object containing the response from the web request.
#>
[CmdletBinding( SupportsShouldProcess = $True )]
[OutputType([Object[]])]
Param (
# String or Here String for SQL Statement
[Parameter( Mandatory = $True, ValueFromPipeline )]
[String]$SQLQuery,
# Return Full Report Object.
[Parameter()]
[Switch]$IncludeFullReport
)
Invoke-HaloPreFlightCheck
try {
$Payload = @(@{id = 0; name= ''; sql = $SQLQuery; apiquery_id = 0; "_testonly" = $false; "_loadreportonly" = $true})
if ($PSCmdlet.ShouldProcess($Payload -is [Array] ? 'Reports' : 'Report', 'Execute')) {
$Report = New-HaloPOSTRequest -Object $Payload -Endpoint 'report'
if (-not $Report.report.load_error) {

if ($Report.report.rows.count -eq 0) {
throw "No results were returned"
}

else {
if ($IncludeFullReport) {
return $Report
}
else {
return $Report.report.rows
}
}
} else {
Throw $Report.report.load_error
}
}

} catch {
New-HaloError -ErrorRecord $_
}
}

0 comments on commit 1e048b7

Please sign in to comment.