According to API Ninja's documentation (link), you need to set the X-Api-Key header.
Here is an untested example:
Code:Public Async Function GetStockPrice(ticker As String) As Task(Of String) If (String.IsNullOrWhitespace(ticker)) Then Throw ArgumentOutOfRangeException(NameOf(ticker)) End If Dim baseUrl As String = "https://api.api-ninjas.com/v1/stockprice" Dim query As NameValueCollection = HttpUtility.ParseQueryString($"ticker={ticker}") Dim url As String = $"{baseUrl}?{query.ToString()}" Dim apiKey As String = "CHANGE ME" Using client As New HttpClient() Using request As New HttpRequestMessage(HttpMethod.Get, url) request.Headers.Add("X-Api-Key", apiKey) Using response As HttpResponseMessage = Await client.SendAsync(request) response.EnsureSuccessStatusCode() Dim responseBody As String = Await response.Content.ReadAsStringAsync() Return responseBody End Using End Using End Using End Function




Reply With Quote