API Updating variable set returns 'Changes to these variables could not be saved'

When attempting to update a variable set through the API the following error is returned

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

This also occurs when just retrieving and sending back without change as below
let vars = Octo.VariableSets.Get(project.VariableSetId) Octo.VariableSets.Modify(vars)

The user has System Admin rights

This only occurs when trying to update an existing variable set, when a variable set is being added to a project through the api then all works as expected.

Hi Bruce;

Do you see any similar issues when updating through the UI? Assuming not, let me know if so.

The line of code that makes this check looks like:

                if (set.Version != resource.Version)
                    return ErrorResponse.BadRequest("Changes to these variables ...");

I.e. the Version on the variable set being sent back to the server needs to match the one the server originally returned. The example you show should definitely achieve that - if you have any ideas along these lines (or can check the versions involved) it might suggest a cause we can investigate.

Cheers,
Nick

HI Nick,

The issue was a mismatch in the Octopus.Client nuget package. I hadn’t updated from the 2.0 version, which doesn’t include the resource.Version property that you mentioned above.

I’ve updated the package and all now good.

Bruce