Update Octopus project variable by POST/PUT call

Hi Team,

Currently , I am working with octopus API call. Can you please help me with example guide how to add or update the octopus project variable by POST or PUT call with curl command from the unix box.

Please advise.

Hi @om.joysaha,

Thanks for reaching out.

I’ve actually written a script that does that. https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/REST/PowerShell/Variables/AddOrEditVariablesWithScoping.ps1

Please do thorough testing and reading before you implement in prod.

Please let me know if it works for you or if you need more assistance.

Thanks,
Jeremy

Hi Team,

This is the powershell script . I am doing the setup in Unix box…can you provide some kind of stuff for that.

Hi,

Unfortunately, we don’t have any bash resources. You could either install Powershell on the box and use it as it is, or adapt the logic to a scripting language you prefer.

Here is a repository of our API scripts: https://github.com/OctopusDeploy/OctopusDeploy-Api/tree/master/REST

PowerShell is our most highly utilized language so if you go that direction you will have a lot of script resources to utilize.

Please let me know if you get it going or need more help.

Thanks,
Jeremy

okay thanks…Is there any swagger rest api call feature for that .I have tried with put call in octopus swagger section for variable update section but getting 400 error with invalid response body.In swagger of octopus there is two input asking one is space I’d and another is id of the variable for put call but no editing option for response body.
Can you please help on that …

Hi,

Are you attempting to do the change to the variable set within swagger?

I would use something like PowerShell/Bash/Postman to do that.

The logic on how the JSON body needs to be edited can be found in my script I linked.

You will need to do a GET call on the variable set, find the variable you want to edit, make the change, then do a PUT call, placing the modified body back in place.

Please let me know if you get it working or need more help.

Thanks,
Jeremy

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