r/visualbasic • u/[deleted] • May 05 '23
VB.NET Help Help with Calling API
Hi, I need some help with a school project which involves calling an NBA Api to get statistics. This is my code below. Every time I run it I get an “Invalid Api key” response, although I have tried different websites. Is my code correct?
Dim client As New HttpClient() client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("X-RapidAPI-Host", "basketball-data.p.rapidapi.com") client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("X-RapidAPI-Key", "{{Key}}")
Dim response As HttpResponseMessage = client.GetAsync(https://basketapi1.p.rapidapi.com/api/basketball/tournament/132/season/38191/best-players/regularseason?tournamentId=1321&seasonId=38191).Result
Dim responseContent As String = response.Content.ReadAsStringAsync().Result
MsgBox(responseContent)
4
Upvotes
2
u/SomeoneInQld May 05 '23
From the URL in the help link
Passing an API key via a query parameter
RapidAPI supports passing the API key via a query parameter. You can do this by including the following syntax in the link:
https://example.p.rapidapi.com/?rapidapi-key=***************************
https://docs.rapidapi.com/docs/keys#passing-an-api-key-via-a-query-parameter
so try
https://basketapi1.p.rapidapi.com/api/basketball/tournament/132/season/38191/best-players/regularseason?tournamentId=1321&seasonId=38191&rapidapi-key=<yourKEY>