Updating deployment processes with REST API - http 400

EDIT: added a new version of the powershell script with redundant lines removed


I’m trying to modify a project’s deployment process via the REST API but i’m getting a generic “400 - bad request” response, and no entries in the Octopus Server logs. It’s possibly I’m misunderstanding how this endpoint works but without any error messages it’s impossible to troubleshoot. I’ve taken some guidance from previous topics on this issue but none of them had any resolution.

My code is attached, here is a description of what it’s doing;

  1. Get the deployment process template. In my case is this is the deployment process for a brand new project so contains no steps or actions.

  2. Get an action template from a different deployment process. This is a fairly simple scripted step based on a custom step template.

  3. Add the action template to the deployment process retrieved in step 1.

  4. Update the deployment process with Put.

Step 4 results in this exception;

Invoke-WebRequest : The remote server returned an error: (400) Bad Request.
At E:\resources\scripts\powershell\wip\dep_proc_poc.ps1:26 char:29
+ ... ntProcess = Invoke-WebRequest -Uri "http://octopus.app.branch.local/a ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId :     WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

If i skip step 3 (no changes) then there is no error. But it seems that any modification to the deployment process before issuing the Put will result in a generic 400 response.

Any advice appreciated!

dep_proc_poc_fixed.ps1 (1.0 KB)

Hey Ryan,

First of all, welcome to the Octopus boards!

I took a look at your script and I think the problem inherently comes from the structure of the JSON for the deployment process is different than the structure of an action template. There is a lot more logic that needs to be implemented in the script to arrange the data correctly in a way that the deployment process JSON will be happy with.

I found an example that does what you are trying to do but it uses C# and also uses Client.dll instead of API calls. The logic should be similar in PowerShell and API calls, so hopefully it should get you a better understanding of the work that needs to be done in your script.

Please let me know if you need any further assistance with this.


Hi Jeremy,

Thanks a lot for your reply. I tried worked from your example but i couldn’t find a way to initialise new step or action resources without using the client dll. Instead I went back a step and tried to clone the step rather than the action, which led me to find the PowerShell example on github below.

I now have this working as intended - it seems the key component I was missing is to unset the Id properties of the process, and of the action within the process’s step. I’ve attached the working script in case it helps anyone else in the future.

Again - thank you for leading me to the solution.

Github example;

Working script;

dep_proc_poc_working.ps1 (1.3 KB)

1 Like

Hey Ryan,

You’re very welcome. I’m glad to hear you got it worked out. Also, thank you for attaching your working script. You never know who will happen upon it when they need it and you’ll make their day.


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