401 Unauthorized

Hi Team,

I’m tring to do a RestAPI POST to start a deployment but I’m getting 401 unauthorized error, the api key is for a user who is able to deploy on Octopus UI.

$apiKey=“API-” #octopus API key

$headers = @{}
$headers.Add(“X-Octopus-ApiKey”,$apikey) #restapi header

$DeploymentBody = @{
ReleaseID = “Releases-7084”
EnvironmentID = “Environments-82”
FormValues = @{ # Here is where you declare all your Prompt variables.
“Variable1” = “SetVariable1”
“Variable2” = “SetVariable2”
UseGuidedFailure=“False” }
} #| ConvertTo-Json

Invoke-RestMethod -Uri “$apiUrl/deployments” -Method Post -Headers $Header -Body $DeploymentBody

Do you have any clue why I am getting the error?



Hi @gszalai,
Thanks for getting in touch! This may be a Header Syntax issue rather than permissions related.

Try updating the header to the following format.

$Header = @{ “X-Octopus-ApiKey” = $apiKey }

Here’s a great example that should help you further,

Give that a try and let me know how it goes.