I have this code to download the file and save it but I don't know the type of the file so when saving it I am having trouble deciding the type.
here is the code
$tokenUrl = "/api/v1/gettoken"
$bodyData = @{
"roles"= @("CONSUMER.ALLFUNCTIONS")
"callingApplicationId"="IZGpLpXoN"
"applicationKey"="XpwR3ayFVtRCbIZGpLpXoNYdBfDQLUVb"
}| ConvertTo-Json
$response = Invoke-RestMethod -Uri $tokenUrl -Method Post -ContentType 'application/json' -Body $bodyData
$token = $response[0].token
$getDocumentUrl = "/api/v1/documents/single/65a6296932aab9ed621a29e1?requestedBy=1361"
$header = @{"token"=$token}
Invoke-RestMethod -Uri $getDocumentUrl -Method Get -Headers $header -OutFile
"C:\code\65a6296932aab9ed621a29e1.tif" #<-- here I need the file type
Here's what I'd do:
-PassThruto make the cmdlet return the HTTP response in addition to writing to fileContent-Typeresponse headerThis approach obviously relies on media types already registered in your Windows installation - in case you need to resolve file types not likely to be found registered on the machine that's going to be running the script, you can pre-seed the mapping table with your own custom mappings: