PowerShell authentication issue

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 {
$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

$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.Add(“accept”, “application/json”)
$headers.Add(“CB-ACCESS-KEY”, “$ACCESS_KEY”)
$headers.Add(“CB-ACCESS-SIGN”, “$SIGNATURE”)
$URI = $BasePath+$RequestPath
$response = Invoke-WebRequest -Uri $URI -Method GET -Headers $headers

1 Like

I resolved the issue. My hex value was returned in uppercase. It needed to be in lowercase.

1 Like