1

I have a Powershell script that I use to synchonize various projects parameters. The relevant code I use to update a project parameter is:

$propName = "ReleaseNumber"
$propValue = "10.0"
Invoke-RestMethod -method Put -uri "$server/httpAuth/app/rest/projects/$targetProject/parameters/$propName" -Body "$propValue"

After the upgrade to TeamCity 9.1, I started receiving the following error when using the script:

Invoke-RestMethod : The remote server returned an error: (415) Unsupported Media Type.

What do I need to do to resolve this issue?

arcain
  • 14,920
  • 6
  • 55
  • 75

1 Answers1

9

By default, the ContentType sent by Powershell's Invoke-RestMethod is application/x-www-form-urlencoded. Prior to TeamCity 9.1, TeamCity didn't seem to care much about the ContentType for the project-related API calls, but with 9.1, and the addition of both XML and JSON payloads, it looks like TeamCity is being more picky about content types. So, since your property values are just plain text, to resolve the problem specify text/plain as the ContentType, like so:

Invoke-RestMethod -contentType "text/plain" -method Put -uri "$server/httpAuth/app/rest/projects/$targetProject/parameters/$propName" -body "$propValue"
arcain
  • 14,920
  • 6
  • 55
  • 75