Setting variable scope with the REST API

Hi all

I’ve been using the code snippet found in the Octopus Documentation here to create and update variables programmatically with the REST API. This is working perfectly.

However I can’t seem to work out how to set the variable scope via the same API. Specifically, I’m trying to set the Environment field to bind the value to the “Development” environment.

I’ve uploaded a copy of my script (without sensitive information), with my attempt at adding the scope property to the payload. I’ve also added a screenshot of the code in case it’s easier to read that way.

Would someone be able to tell me where I’ve gone wrong here please? I can’t find any page in the documentation or anywhere on Stackoverflow etc. that illustrates this.

Set-Variables.ps1 (2.0 KB)

Thanks very much.

Hi Chris,

Thank you for contacting Octopus Support.

I’m going to see if I can get this worked out in a test environment. I’ll touch base again shortly.

Thanks for your patience.


Hi Chris,

Thank you for your patience.

Here is a modified version of the script you are using that includes the ability to scope to an environment:

Let me know if that does the trick.


Hi Donny

That’s really useful thanks very much. It worked a treat.



1 Like

Hi Chris,

Thank you for getting back to me. I’m glad this worked for you.

Don’t hesitate to reach out if you need anything else.


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