Unable to create Secret Variables in One-Way Git Sync using Api

Product: PowerShell Universal
Version: 4.5.5


I created an app to create secret variables using Api calls in our lab, which doesn’t have one-way gitsync on, and it’s working great. Here is a snippet of the pertinent code:

Invoke-RestMethod http://localhost:5000/api/v1/signin -Method POST -Body ( @{ username=$Secret:XXXXXX.UserName password=$Secret:XXXXXX.GetNetworkCredential().Password} | ConvertTo-Json ) -SessionVariable SessionVar -ContentType ‘application/json’

$Body = @{

name = $Eventdata.SecretStringName

type = ‘System.String’
value = $Eventdata.SecretStringValue
vault = ‘Database’

}

Invoke-RestMethod -Uri http://localhost:5000/api/v1/variable -Method POST -ContentType ‘application/json’ -Body ($Body | ConvertTo-Json) -WebSession $SessionVar

When I try running the same app on our server with one-way git sync enabled I am getting an error: “The remote server returned an error: (400) Bad Request.”

It appears it is not possible to create variables in a One-Way Git Sync environment even via Api? Unless I’m missing something? What would be the Ironman Software recommended best way to create new secret variables in a one-way sync environment?

I figured out a suitable workaround for my app. I modified it to add a line to the variables.ps1 for my new variable. Once the new variable can be seen in PSU, it sends a PUT method to the variables api which updates it our SQL database. Mission accomplished.