Created
September 28, 2021 21:07
-
-
Save onesmartguy/69974f717b3865f2cdb79115a7f9d0db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$API_KEY = "1E71E4E5-F2FD-44F4-B058-71C88E420096" | |
$API_DOMAIN = "https://help.calibercollision.com" | |
$API_REQUEST_SEARCH_PATH = $API_DOMAIN + "/api/v3/requests?TECHNICIAN_KEY=${API_KEY}&input_data={0}&format=json" | |
$API_REQUEST_PATH = $API_DOMAIN + "/api/v3/requests/{0}?TECHNICIAN_KEY=${API_KEY}&format=json" | |
$API_REQUEST_ATTACHMENT_PATH = $API_DOMAIN + "/api/v3/requests/{0}/attachments/{1}/download?TECHNICIAN_KEY=${API_KEY}" | |
Function ExcelToCsv ($File) { | |
$Excel = New-Object -ComObject Excel.Application | |
$wb = $Excel.Workbooks.Open($File) | |
foreach ($ws in $wb.Worksheets) { | |
$ws.SaveAs($File + ".csv", 6) | |
} | |
$Excel.Quit() | |
} | |
Function Get-ManageEngineRequests { | |
[cmdletbinding()] Param ($filters) | |
# End of Parameters | |
$inputData = ConvertFrom-Json @" | |
{ | |
"list_info": { | |
"row_count": "500", | |
"sort_field": "created_time.display_value", | |
"search_fields": [], | |
"sort_order": "asc" | |
} | |
} | |
"@ | |
$inputData.list_info.search_fields = $filters | |
$inputData = $inputData | ConvertTo-Json -Compress | |
Write-Host $inputData | |
$request_url = $API_REQUEST_SEARCH_PATH -f $inputData | |
Write-Host $request_url | |
$response = Invoke-WebRequest -Method GET -Uri $request_url -UseBasicParsing | |
$result = ConvertFrom-Json $response.content | |
$requests = $result.requests | |
return $requests | ConvertTo-Json | |
} | |
Function Get-ManageEngineRequest { | |
[cmdletbinding()] Param ([int] $requestId) | |
$request_url = $API_REQUEST_PATH -f $requestId | |
Write-Host $request_url | |
$response = Invoke-WebRequest -Method GET -Uri $request_url -UseBasicParsing | |
$result = ConvertFrom-Json $response.content | |
if(($result.response_status.status_code -ne 2000) -and (@($result.request.attachments).Count -eq 0)){ | |
return "No Attachments Found"; | |
} | |
$request = $result.request | |
$file = $request.attachments.where{$_.content_type -match 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'} | Select-Object name,id | |
Write-Host $file[0] | |
if(@($file).Count -eq 0) { | |
return 0 | |
} else { | |
$download_url = $API_REQUEST_ATTACHMENT_PATH -f $requestId, $file[0].id | |
$fileName = $file[0].name | |
$filePath = (Get-Location).Path + '\' + $fileName | |
Write-Host 'path: '+ $filePath | |
Invoke-WebRequest $download_url -OutFile $filePath | |
ExcelToCsv($filePath) | |
return $download_url | |
} | |
} | |
$options = ConvertFrom-Json '{"subject":"ASP ", "status.name": "Open" }' | |
# Get-ManageEngineRequests $options | |
Get-ManageEngineRequest 1670631 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment