API call to VariableSets doesn't bring back JSON format

I am writing a seemingly simple application to interrogate variables in deployments.
I have several test queries on user/teams etc and all work fine.

However when I try to look at variables using the following code it returns a cast error.
Unable to cast object of type ‘System.String’ to type ‘System.Collections.Generic.IDictionary`2[System.String,System.Object]’.

client.Authenticator = new RestSharp.Authenticators.SimpleAuthenticator(“username”, Username, “password”, Password);

var request = new RestRequest(“api/variables/names”, Method.GET);

request.RequestFormat = DataFormat.Json;
request.AddHeader(“X-Octopus-ApiKey”, “myapikey”);

var response = client.Execute(request);
JsonDeserializer deserial = new JsonDeserializer();

var JSONObj = deserial.Deserialize<List>(response);

For all other queries the response.content contains a string starting and ending with {\r\n … \r\n}
However, this query’s response.content starts and ends with [\r\n…\r\n]

Am I doing something wrong or is there a problem with the API call and its resolution to JSON format?


Hi Lee,

Thank you for reaching out! What’s happening is your API endpoint returns a list of strings, and not a list of Octopus variable sets. If you are wanting to retrieve variable sets within one specific deployment, first you need to find the DeploymentId. You can list out the deployments to find the one you want to use using the endpoint:
Then with the DeploymentId, use (inputting your ID):
And that will give you the variables available at the time of deployment which you can then use in your JSON.

I hope that helps!



This issue has been closed due to inactivity. If you encounter the same or a similar issue and require help, please open a new discussion (if we asked for logs or extra details in this thread, consider including them in the new thread). If you are the creator of this thread and believe it should not be closed let us know via our support email.