Issue with custom Content-Type on PowerShell Azure Function (v2/v3) Error 415 (Unsupported Media Type)
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 215
- Avg merge
- 4h 2m
- Merged PRs (30d)
- 1
Description
Hi,
I'm fighting with a debug since few days with a PowerShell Azure Function. In fact, It's just a very small script that call an another external API (Terraform Cloud API) who need a specific custom Content-Type "application/vnd.api+json"
So, I've for example this script who works on PS5 and PS Core 6 locally ->
```ps
$tf_organization = "SANDBOX2"
$tf_token = "***********"
$tf_api_uri = "https://app.terraform.io/api/"
$tf_api_version = "v2"
$tf_api = $tf_api_uri + $tf_api_version
$tf_headers = @{
'Authorization'="Bearer $tf_token"
'Content-Type'="application/vnd.api+json"
}
$team_id = "team-xxxxxxxxxx"
$api_operation = "/teams/$team_id/authentication-token"
$api_method = "Post"
$api_uri = $tf_api + $api_operation
Write-Output "API $api_uri"
$ContentType = "application/vnd.api+json"
Invoke-RestMethod -Uri $api_uri -Method $api_method -Headers $tf_headers -ContentType $ContentType
```
This script works correctly and got my TF team token from API.
Then, so I just put a similar script on new Azure Function (trying v2/v3) with just this ->
```ps
using namespace System.Net
param($Request, $TriggerMetadata)
Write-Host "PowerShell HTTP trigger function processed a request."
$tf_organization = "SANDBOX2"
$tf_token = "*********"
$tf_api_uri = "https://app.terraform.io/api/"
$tf_api_version = "v2"
$tf_api = $tf_api_uri + $tf_api_version
$tf_headers = @{
'Authorization'="Bearer $tf_token"
'Content-Type'="application/vnd.api+json"
}
$team_id = "team-xxxxx"
$api_operation = "/teams/$team_id/authentication-token"
$api_method = "Post"
$api_uri = $tf_api + $api_operation
Write-Output "API $api_uri"
$ContentType = "application/vnd.api+json"
Invoke-RestMethod -Uri $api_uri -Method $api_method -Headers $tf_headers -ContentType $ContentType
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $status
Body = $tf_org_team_token
})
```
If I run this script directly from Azure Function, I get an error from API server who say http status 415 (Unsupported Media Type). I can have this error locally, If I didn't specify Content-Type or don't use the expected one.
So, I suspect that Azure Function rewrite or something similar, and can't send my custom Content-Type "application/vnd.api+json" who is need by the remote API server.
Is it a limitation ? a know issue ?
I try to look for anywhere, and see almost issue about C# but not PS functions.
Thanks,
Regards
Alexandre
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.