Unauthorized error of brokerage/products, what am I doing wrong?

Hi, I got the simple error on the commandline : unauthorized & vblf

Here is the code in VB.net:

Imports System.Security.Cryptography
Imports System.Text
Imports RestSharp
Imports RestSharp.Authenticators

Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim baseUrl As String = “https://api.coinbase.com
Dim m_CBapikey As String = Environment.GetEnvironmentVariable(“CB_APIKEY”)
Dim m_CBseckey As String = Environment.GetEnvironmentVariable(“CB_SECKEY”)
Dim requestPath As String = “/api/v3/brokerage/products”
Sendrequest(m_CBapikey, m_CBseckey, baseUrl, requestPath)
End Sub
Sub Sendrequest(apiKey As String, apiSecret As String, baseUrl As String, requestPath As String)
Dim client As New RestClient(baseUrl)
Dim request As New RestRequest(requestPath, Method.Get)
Dim m_Method As String = “GET”

    Dim timestamp As String = DateTimeOffset.Now.ToUnixTimeSeconds()
    Dim queryString As String = timestamp + m_Method + requestPath
    Dim sign As String = CreateSignature(queryString, apiSecret)

    request.AddHeader("CB-ACCESS-TIMESTAMP", timestamp)
    request.AddHeader("CB-ACCESS-KEY", apiKey)
    request.AddHeader("CB-ACCESS-SIGN", sign)
    request.AddParameter("application/x-www-form-urlencoded", queryString, ParameterType.RequestBody)

    Dim response As RestResponse = client.Execute(request)

End Sub
Function CreateSignature(queryString As String, apiSecret As String) As String
    Dim hmac As HMACSHA256 = New HMACSHA256(Encoding.UTF8.GetBytes(apiSecret))
    Dim signatureBytes As Byte() = hmac.ComputeHash(Encoding.UTF8.GetBytes(queryString))
    Return BitConverter.ToString(signatureBytes).Replace("-", "").ToLower()
End Function

End Class

Can you help me ? Thx in advance GWEPPD


Welcome to the Coinbase Cloud forum! While we are still looking into your request, we would like to let you know that our support is limited to the information and resources available in our Public documentation in reference to Advanced Trade here: Advanced Trade API | Coinbase Cloud

We don’t support individual code review as of the moment. However we will try our best to look into this further and get back to you. We request your patience while we look into your request.

Hi support,

Thanks for fast answering. In many articles in this form I noticed that you ask for code(snippets) to examine the clients problem, so I thought I send the whole code directly to you. I understand what you are saying, so I carry on, trying to make requests and in the meantime I wait for your examination.
Regards, GWEPPD

Good day Caleb,

I managed to get a response for “/api/v3/brokerage/products”, after some
modifications to my code.
A status code 200 was received and I thought I was getting a list of “currency pairs” etc.,
however, it turned out to be the message below with an HTML document behind it.

This is the first part of the response, followed by another HTML document:

StatusCode: 200, ReasonPhrase: ‘OK’, Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
Date: Sun, 25 Jun 2023 13:08:01 GMT
Transfer Encoding: chunked
Connection: keep alive
ETag: W/“d03a5c0a2ccebc8784cf2edad6243024”

What’s going wrong?

Regards, GWEPPD.