I have the same script written in Python and PowerShell. Python works; PowerShell doesn't.
Both are making the same REST API call. It is meant to download the Work Order report with attachments. The attachments are included in the Python script, but the PowerShell script only downloads the Work Order report itself, no attachments. Is there some difference in the implementation of "Invoke-RestMethod" that changes how the call is made? I've also tried "Invoke-WebRequest" with the same results, no attachments. Is there something else to try in PowerShell? Can anyone verify this behavior in their environment?
Python:
headers = {
'Accept': 'application/PDF',
'apikey': '<apikey goes here>'
}
url = f'{host}/maximo/api/os/mxapiwodetail?action=genreport&reportname=woprint.rptdesign&oslc.where=wonum="{wonum}"&reportformat=pdf&attachments=1'
response = requests.get(url, headers=headers, verify=False)
with open(rf'{downloadPath}\{pdfFileName}', "wb") as f:
f.write(response.content)
PowerShell:
$headers = @{
"Accept" = "application/PDF"
"apikey" = "<apikey goes here>"
}
$url = $hostname/maximo/api/os/mxapiwodetail?action=genreport&reportname=woprint.rptdesign&oslc.where=wonum="$wonum"&reportformat=pdf&attachments=1"
$response = Invoke-RestMethod -Uri $url -Headers $headers -Method GET -OutFile $pdfFilePath -ErrorAction Stop
------------------------------
Jason Johnson
------------------------------