Powershell - Invoke-RestMethod : The remote server returned an error: (400) Bad Request

$baseUri = “http://octopus.url” # ← Update this to the base URL to your Octopus server(i.e. not including ‘app’ or ‘api’
$apiKey = “API-xxxxxxxxxxxxxxxxxxxxxxxxxx” # ← Update this to your API key
$headers = @{“X-Octopus-ApiKey” = $apiKey}
$InterruptionID = “Interruptions-xxx”
$body = @{Instructions= “”
Notes = “Message” #message
Result=“Proceed” #Set this property to “Abort” to abort the deployment
} | ConvertTo-Json

Invoke-RestMethod -Method Put -Uri “$OctopusURL/api/interruptions/$InterruptionID/responsible” -Body $body -Headers $header

Hi @nithi.nithin09 ,

Welcome to the community, and thanks for contacting us regarding your question!

Do you mind if I ask where you’re getting this template for your API call? It’s possible we have changed some of the data structure in the body Octopus is expecting in the API call, and this may be an older form of a request.

More details about the API call and the json body your current Octopus version is expecting is to manually perform the action in the Octopus portal while watching network traffic in a browser via F12 > Network tab. Feel free to send us a screenshot of these, and we can help diagnose the API responses associated with your call.

Best,

Hello @patrick.smergut
Thank you for the response ,kindly help on the below
octopus version : 2020.4.6
My intention is to write a powershell to assign interruption to my name and proceed with the deployment and the input parameter will be From environment,To enviornment and Project name
image

Hi @nithi.nithin09 ,

Thank you for providing those details on what you’re attempting to do with the manual intervention.

You should be able to use the following script and adapt it to your needs, though you will need to set the Interruption ID by knowing which number it will at runtime, or determine it programmatically.

As for the input parameters you mention, are you hoping to enter these in the Notes section? If so, you should be able to use the ‘Notes’ in the body of the example script above to do so.

Please let us know if this is helpful or if there is anything further we can provide.

Best,
Patrick

@patrick.smergut thanks for the help, it’s worked.

We are triggering these deployment from teamcity -’ OctopusDeploy: Promote release’ step

Is there any way to pass required parameter(Notes = “Message” and Result = “Proceed” ) and get assigned to my name and proceed with deployment automatically without touch from octopus

Hi @nithi.nithin09 ,

I’m happy to hear the script worked for you, and thank you for getting back to us with your additional question.

Would you be able to provide me with a high-level use case for this manual intervention step? If I know your end goal we might be able to approach this problem from a different angle. Otherwise a manual intervention step may not be needed if this process is to be automated, so further details on your process would help us better answer your question.

Best,
Patrick

Higher environment deployment should happen through authorized API keys.
in case of batch deployments this will helpful.

is there any way to pass parameter from teamcity deploy step and use it from octopus deployment step.

Hi @nithi.nithin09 ,

Thank you for getting back to us with further details on your use case.

Sorry to press with more questions, but I wondered if you could elaborate a little more on how you would like the process for using authorized API keys to control higher environment deployment to work? The more details you can provide, the better solution I can give you.

As for passing parameters from TeamCity to Octopus, it may be better if you use the CLI with the deploy-release command. This command allows the use of prompted variables and a few other arguments for API key and specifying a user. You can find more information here: Deploy release - Octopus Deploy

Please let us know if the above is helpful or if there are any further questions we can answer.

Best,
Patrick