What is the right way to invoke Octopus REST API from the script running on Octopus as deployment step?

I understand how to run Powershell scripts as deployment steps and how to operate on Octopus variables in those scripts. But what if built-in variables do not provide enough information and I need to invoke REST API from that script to get what I need? How shall I invoke Octopus API from the script running on Octopus? Again I know how to invoke Octopus API from the outside script, say from TeamCity. But doing the same from within does not look quite right. For instance, where that script supposed to get access token from? Keep it as Sensitive variable? Is there better way?

Thank you!
Konstantin

Hi Konstantin,

Having the API Key or the Password of the user to want to impersonate in the API calls as a sensitive variable, and then calling the API the same way you would from any other Powershell script (like you seem to be doing in TC) using that sensitive variable would be the way to go.

Regards,
Dalmiro