This is an interesting one. We have not been able to reproduce. Your script works for us!
For example, this was the script we used:
$apiKey = "API-1234"
$OctopusURL = "http://YOUR_SERVER"
$header = @{ "X-Octopus-ApiKey" = $apiKey }
$projectSlug = "testing-testing-123"
$releaseNumber = "0.0.2"
#Getting the project
$project = Invoke-WebRequest -Uri "$OctopusURL/api/projects/$projectSlug" -Headers $Header| ConvertFrom-Json
if (!$project) {
Write-Host("Failed to find project with name $($projectSlug).")
Exit
}
#Getting the project's release
$release = Invoke-WebRequest -Uri "$OctopusURL/api/projects/$($project.id)/releases" -Headers $header| ConvertFrom-Json | select -ExpandProperty Items | ?{$_.version -eq $releaseNumber}
if (!$release) {
Write-Host("Failed to find release $($releaseNumber).")
Exit
}
#Updating Release's variable snapshot
Invoke-WebRequest -Uri ("$OctopusURL" + "$($release.Links.self)/snapshot-variables") -Method Post -Headers $Header
The only way we were able to get the same error message was if we changed Post to Put on this line:
Invoke-WebRequest -Uri ("$OctopusURL" + "$($release.Links.self)/snapshot-variables") -Method Post -Headers $Header
I’m wondering if, for some environmental reason, your server may not like POST requests from PowerShell like this. If you change that to a Put request, do you see any difference?
An example of that would look something like this:
Add-Type -Path 'C:\PathTo\Octopus.Client.dll'
$apikey = 'API-1234' # Get this from your profile
$octopusURI = 'http://YOUR_SERVER' # Your Octopus Server address
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey
$repository = New-Object Octopus.Client.OctopusRepository $endpoint
$projectName = "Testing testing 123"
$project = $repository.Projects.FindByName($projectName);
if (!$project) {
Write-Host("Failed to find project with name $($projectName).")
Exit
}
$releaseVersion = "0.0.2"
$release = $repository.Projects.GetReleaseByVersion($project, $releaseVersion);
if (!$release) {
Write-Host("Failed to find release with version $($releaseVersion).")
Exit
}
# Update snapshot
$repository.Releases.SnapshotVariables($release)
Write-Host("Success")
Ultimately that should be invoking the same requests behind the scenes, so we’d be interested to see if you get the same error when using OctopusClients.