Is it possible to use a UAVariable in an API endpoint?

Product: PowerShell Universal
Version: 2.1.2

I have a UAVariable secret defined that I would like to use in one of my endpoints, the variable doesn’t show up and it looks like using Get-UAVariable doesn’t return anything. Is it possible to use variables in API endpoints?

These should be showing up in the API Endpoint automatically. For example, if you have a secret with the name MyPassword, it should just be $MyPassword in the API.

If that’s not happening then we either have a bug or your environment isn’t configured to use all variables. This is the default setting so if you haven’t configured any environments then that is not the problem.

Get-UAVariable does not return the value of secrets through the management API. If you want to retrieve a secret directly, you can use the Get-Secret cmdlet directly in the API. We use the 0.2.1 version of the Microsoft.PowerShell.SecretManagement to store secrets in Universal. Internally, we are just calling this cmdlet to populate the variable within the API script blocks.

It turned out that the variable was not added to my environment, added the variable and not it’s working as expected.

1 Like

Glad you got it working! We do have an issue that may cause this as you shouldn’t have to define each variable manually and they should be available by default. This has been resolved in our main branch and will be available in 2.3.0.