I’m trying to add a new variable to a variable set in Octopus using the Rest API.
The first time, I ran: curl -X PUT my-octo/api/{spaceid}/variables/${varID} -H X-Octopus-ApiKey:**** -H Content-Type:application/json -d '{"Name":"something", "Value":"something", "Type":"String", "IsSensitive" : false}'
I go a json back. Did not seem to be an error. However, when I look in the UI or when I using the API to GET my-octo/api/{spaceid}/variables/${varID} I do not see any variable.
Now, if I try to run the PUT request, I get the following error:
“Changes to these variables could not be saved, because another user has made changes to the variables between when you started editing and when you saved your changes. Please reload or open a new tab to make your changes.”
Since I added the variable with a Scope, I cannot add anymore variables, I keep getting the error: { "ErrorMessage": "Object reference not set to an instance of an object." }
When I look at the audit on Octopus UI, it seems that it updated the variable “RelatedDocumentIds”: [] which I did not have in my script. It updated it with my environment ID.
Even if I run my PUT request with “RelatedDocumentIds”: [] it throws the Object error. Any help would be appreciated. Thank you
I’m not sure what exactly would be causing that error, but you might have better luck trying this script:
It should allow you to create new and update existing variables with or without scoping and succeed without getting that error again. I know it looks complicated, but there is a section towards the bottom to enter the desired values.