Deployment via the API - specifying Rel/Env/Spec machine by name, not ID

Hi all, I’m trying to do a deploy via powershell, via the API but this has complicated things a lot and I’m hoping for a workaround.

When I do the appropriate post, it requests the internal ids for ReleaseId, EnvironmentId and SpecificMachineIds, like this:

$body=("{"ReleaseId":"Releases-16975",
"EnvironmentId":"Environments-187",
"SkipActions":[],
"SpecificMachineIds":["Machines-2509","Machines-2510"],
"QueueTime":null,
"FormValues":{},
"ForcePackageDownload":false,
"UseGuidedFailure":false}")

$json=Invoke-WebRequest -uri “http://myinstance.octopus.com/api/deployments?apikey=API-QWERTYUIOP” -Method POST -Body $body

This works, but I want to be able to do this with the actual names, not the ids. Is this possible?

If not, what’s the simplest way to get the ids via the API based on the field names instead?

Thanks.

I can find the Name based on the id, is there a way to do the reverse perhaps?
http://myinstance.octopus.com/api/environments/Environments-187

Hi,

Thanks for reaching out!

There are a few ways to get this done:

Using Octoposh

Octoposh is an open source Powershell module for Octopus which has a few cmdlets that can help you look for things by their name, like Get-OctopusEnvironment -Name Production, Get-OctopusRelease -version 1.0.0 and Get-OctopusMachine -name MyVM. All of those will return an object which will have an ID property that you can later on use in your Invoke-WebRequest call.

Octoposh site: http://octoposh.net/
Octoposh wiki: https://github.com/Dalmirog/OctoPosh/wiki

Using the raw API to get the resources and filter by name
Code will say more than words in this case: https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/REST/PowerShell/Deployments/DeployExistingReleaseToSpecificSingleMachine.ps1

Hope that helps!
Dalmiro

Thanks Dalmiro, nice repo there, I’ll be referring to it quite a bit I expect.
Cheers, Ben.