Creating channel rules via the REST api

Hiya,

I’m trying to create a channel via the rest api, but its failing as it doesn’t understand the actions associated with the rule.

Unhandled error on request: https://deploy.servername.co.uk/api/channels by ApiUser : Error converting value "Deploy Files" to type 'Octopus.Client.Model.ReferenceCollection'. Path 'Rules[0].Actions', line 11, position 49.
Newtonsoft.Json.JsonSerializationException: Error converting value "Deploy Files" to type 'Octopus.Client.Model.ReferenceCollection'. Path 'Rules[0].Actions', line 11, position 49. ---> System.ArgumentException: Could not cast or convert from System.String to Octopus.Client.Model.ReferenceCollection.

The documentation on the rules section is a little sparse.

I’m passing through the rules the same way that I’m retrieving them from the API which is:

"Rules": [
	{
	  "Id": "[new guid here]",
	  "Actions": [
		"Deploy Files"
	  ],
	  "VersionRange": "[1611.0,1611.99]",
	  "Tag": ""
	}
  ]

I’m guessing the actions section on POST needs to be some form of action id instead from the deployment steps but I’m struggling to find out exactly what format this should be in?

Thanks,
Ste

I’ve managed to fix this now. It was actually a problem with PowerShell…

The ConvertTo-Json cmdlet has a default depth of 2 for some reason so any objects in nested objects more than 2 levels down basically are just converted to strings.

ConvertTo-Json -Depth 10

The above did the trick. A couple more tweaks and all is working :slight_smile: