-
-
Save pstephenson02/3cf2dc3b9d68db28722ad568c9eb49eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$octopusUrl = 'https://samples.octopus.app' | |
$username = 'admin' | |
$password = 'your-password' | |
$loginPath = "$octopusUrl/api/users/login" | |
$response = Invoke-WebRequest -Method Post ` | |
-Uri $loginPath ` | |
-Body (@{'Username' = $username;'Password' = $password} | ConvertTo-Json) ` | |
-UseBasicParsing ` | |
-SessionVariable 'session' | |
$userId = ($response.Content | ConvertFrom-Json).Id | |
$csrfToken = $session.Cookies.GetCookies($loginPath) ` | |
| Where-Object { $_.Name.StartsWith('Octopus-Csrf-Token') } | |
$sessionToken = $session.Cookies.GetCookies($loginPath) ` | |
| Where-Object { $_.Name.StartsWith('OctopusIdentificationToken') } | |
$headers = @{ | |
'Cookie' = $sessionToken.Name + '=' + $sessionToken.Value | |
'X-Octopus-Csrf-Token' = $csrfToken.Value | |
} | |
Invoke-RestMethod -Method Post ` | |
-Uri "$octopusUrl/api/users/$userId/apikeys" ` | |
-Headers $headers ` | |
-Body (@{'Purpose'='Automation'} | ConvertTo-Json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment