Can't create release through API

I’m trying to create release though the rest api.
I’m able to view all releases on a project at this api endpint

GET /api/projects/Projects-1/releases

According to the API documentation, to create a new release you access this endpoint

POST /api/releases

Yet no matter what I try, I get this error

{
  "ErrorMessage": "Value cannot be null.\r\nParameter name: instance",
  "FullException": "Value cannot be null.\r\nParameter name: instance\r\nSystem.ArgumentNullException\r\n   at System.ComponentModel.DataAnnotations.ValidationContext..ctor(Object instance, IServiceProvider serviceProvider, IDictionary`2 items)\r\n   at Nancy.Validation.DataAnnotations.DataAnnotationsValidatorAdapter.Validate\r\n   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)\r\n   at Nancy.Validation.DataAnnotations.PropertyValidator.Validate(Object instance, NancyContext context)\r\n   at Nancy.Validation.DataAnnotations.DataAnnotationsValidator.Validate(Object instance, NancyContext context)\r\n   at Octopus.Server.Web.Infrastructure.Api.Responder`1.BindAndValidate[TModel]() in Responder.cs:line 65\r\n   at Octopus.Server.Web.Infrastructure.Api.CreateResponseDescriptor`2.Responder.Execute() in CreateResponseDescriptor.cs:line 0\r\n   at Octopus.Server.Web.Infrastructure.Api.Responder`1.Respond(TDescriptor options, NancyContext context) in Responder.cs:line 145\r\n   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)\r\n   at Octopus.Server.Web.Api.OctopusRestApiModule.<>c__DisplayClass0_0.<.ctor>b__0(Object o) in OctopusRestApiModule.cs:line 46\r\n   at Nancy.Routing.Route.<>c__DisplayClass4.<Wrap>b__3(Object parameters, CancellationToken context)"
}

I’ve tried

POST /api/releases

POST /api/releases?Version=1.0.1

POST /api/releases?Version=1.0.1?ProjectID=Projects-1

How can I create a release though the API?

Hello,

Thanks for getting in touch. I got that same errorwhen I had the version and project only as query parameters (sorry that it’s not a helpful error). They need to be submitted in the BODY of the POST request, as JSON.

When I tested this via the Postman tool, my JSON was like this (I attached a screen shot):

{
  "ChannelId" : "Channels-241",
  "ProjectId" : "Projects-241",
  "SelectedPackages" : [],
  "Version" : "0.0.4"
}

We also have a PowerShell example that may help you set up your post request to get around the error: https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/REST/PowerShell/Releases/CreateRelease.ps1

If you haven’t already, you could also consider making use of octo.exe to make the API calls for you, see our detailed documentation here: https://octopus.com/docs/api-and-integration/octo.exe-command-line/creating-releases

Regards,
Nick

Thanks that worked.

The equivalent in powershell

$params = @{}
$params.ChannelId = "Channels-1"
$params.ProjectId = "Projects-1"
$params.SelectedPackages = @()
$params.Version = "1.0.2"

$body = $(ConvertTo-Json $params)

$headers = @{}
$headers."X-Octopus-ApiKey" = "API-xxxxxxxx"

Invoke-WebRequest -Uri https://octopus.example.com/api/releases -Method POST -Body $body -Headers $headers