Get Environment ID from Name using Rest API

I want to get Environment ID using the Name
While it does fetch them for me but is returning a number of environments that have it as a partial name as well.

For example,
EnvName = P2
But I am getting Env ID for, P2, P2-Blue, P2-Green by invoking the following
$octopusURL/api/environments?name=P2

How can I get the Environment ID for just P2 named environment?

Same thing for projects as well.
I want to get the project ID for Project with the name “XYZ”, and not for all “xyz-123”, “xyz-bla-bla”

Possible with Rest API?

Hi Naman,

Thanks for getting in touch! I’m sorry for the confusion here. In short, the answer is ?name= has always returned partial results in this way, and while we now suggest using ?partialName= to do the same, the way ?name= works was left unchanged for backwards compatibility.

I don’t believe there will be an out-of-the-box way to get exact results, unfortunately. I imagine you would need to either:

  • rename the base object so as to avoid getting partial results returned, e.g. P2P2x so a search for ?name=P2x does not include P2-..., or
  • grab the full list that is returned and filter that list afterward to get the single one you want (I don’t have a sample script handy to do this currently, however)

I hope that helps in some way, and please let me know what you think or if you have any further questions.

Best regards,

Kenny