I am not able to authenticate using PowerShell. I am using the Coinbase Time Service API to get the UNIX time for my requests. I keep getting “Unauthorized” with the Invoke-WebRequest command on every request. Below is my code. can anybody assist?
Thank you in advance.
Function Get-AdvCoinSystemTime {
[CmdletBinding()]
Param()
$TimeInfo = Invoke-WebRequest -uri https://api.coinbase.com/v2/time
Write-Output (($TimeInfo.Content | ConvertFrom-Json).Data.epoch)
Write-Verbose “$((Get-Date).ToShortTimeString()) – Get-AdvCoinSystemTime”
Write-Verbose “Time: $(($TimeInfo.Content | ConvertFrom-Json).Data.epoch)”
}
Create Signature
API Data
$ACCESS_KEY = “< REDACTED >”
$APISecret = “< REDACTED >”"
$TimeStamp = Get-AdvCoinSystemTime
$BasePath = “https://coinbase.com”
$RequestPath = “/api/v3/brokerage/accounts”
$Message = “$TimeStamp”+“GET”+“$RequestPath”
Get the HEX of the message.
$SIGNATURE = Get-AdvCoinSHA256 -message $Message -Secret $APISecret -Algorithm SHA256 -Format HEX
$headers=@{}
$headers.Add(“accept”, “application/json”)
$headers.Add(“CB-ACCESS-KEY”, “$ACCESS_KEY”)
$headers.Add(“CB-ACCESS-SIGN”, “$SIGNATURE”)
$headers.Add(“CB-ACCESS-TIMESTAMP”, “$TIMESTAMP”)
$URI = $BasePath+$RequestPath
$response = Invoke-WebRequest -Uri $URI -Method GET -Headers $headers
$response