How to change the state of deployment/release through API

Hi Team,

I have a release which is failed, but i need to change the status of the release from “FAILED” to “CANCELLED”.

I can see an option available to change the state manually, as seen in the below image.

But, i should change the state on fly through API, so i found a method from SWAGGER UI, from where i use below command to get the info the the particular release.

$OctopusAPIKey=“xyz”
$header = @{ “X-Octopus-ApiKey” = $OctopusAPIKey }
Invoke-WebRequest “http://octopus.xyz.com/api/tasks/ServerTasks-23030/” -Method get -Headers $header

from this am getting the info of the release, but when i use post method to change the state from failed to cancelled, by using below command.

$OctopusAPIKey=“xyz”
$header = @{ “X-Octopus-ApiKey” = $OctopusAPIKey }
Invoke-WebRequest “http://octopus.xyz.com/api/tasks/ServerTasks-23030/failed” -Method POST -Headers $header

I am getting either bad request error of “404 NOT FOUND” error.

Can you please help with this, as what is the perfect method to change the state of a release through API.

what should be modified from the above command so that i can change the state of release from API.

It will be very helpful, if we can change the state through API, you solution to this problem will help us a lot.

Thanks,
Shaik Sadiq

Hi there

Thanks for getting in touch! Sorry to see that our docs aren’t as clear as they could be here.

It looks like you’re trying to post to a failed endpoint. What you need to do is post some json with a body & state field to the state endpoint instead:

$apikey="xyz"
$header = @{ "X-Octopus-ApiKey" = $apikey }
$body = @{ State = 'Failed'; Reason = 'Cos I said so'; } | ConvertTo-Json
Invoke-WebRequest "http://octopus.xyz.com/api/tasks/ServerTasks-23030/state" -Method POST -Headers $header -Body $body

Hope that helps!

Cheers,
Matt

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.