Is the PUT operation for Variable setup?

I am trying to create a script that will run Rest APIs on Octopus Deploy to copy a Variable Set from one Octopus Deploy Space to another. To do this I need to run a POST to create the Variable Set (which seems to be fine). I then need to run a PUT operation on the Variables in the new Variable Set.

When I go to the swagger page, and find the put operation that says it “Updates a variable set” it does not have a parameter for the actual variables. (Just takes the space and an id.):

How can I use the Octopus Rest API to add a variable to an existing Variable Set?

Hi @OctopusSchaff,

Thanks for reaching out.

We have some example scripts in our repo here that should get you in a good state, you may need to edit them to serve your specific scenario: OctopusDeploy-Api/REST/PowerShell/Variables at master · OctopusDeploy/OctopusDeploy-Api · GitHub

As with all scripts we suggest, please read them thoroughly and test in a test environment before using in prod.

Please let me know how it goes.


Thank you for pointing me at that.

FYI: Looking at lines 190-193 of the AddOrEditVariablesWithScoping script it looks like that PUT operation expects a body that is not shown in the Swagger document (see my picture above).

Not sure if that is considered a bug, but it would have helped me out if it had shown that the body is expected and the format it expects.

Hi @OctopusSchaff,

You’re right, it should have a body there and indicate that in swagger. I will report this internally to get our swagger updated in future versions.

Hopefully the script helped you get where you needed to go.

Please let me know if it worked for you or if you have other questions.