I’m having trouble connecting VBA Excel with RapidAPI to fetch domain registration details. I’ve searched through several forum posts but haven’t found a working solution yet.
My goal is to read domain names from column A in my spreadsheet and populate column B with the registration information using an API service. The code runs without errors but doesn’t return the expected data.
Function FetchDomainInfo(siteName As String)
Dim response, apiUrl, requestData As String
Dim httpRequest, resultData, parsedJson As Object
Set httpRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
apiUrl = "https://jsonwhois.p.rapidapi.com/api/v1/whois/"
httpRequest.Open "GET", apiUrl, False
httpRequest.setRequestHeader "authorization", "Token token=your_token_here"
httpRequest.setRequestHeader "x-rapidapi-host", "jsonwhois.p.rapidapi.com"
httpRequest.setRequestHeader "x-rapidapi-key", "your_api_key_here"
requestData = "domain=" + siteName
httpRequest.Send (requestData)
response = httpRequest.responseText
Set parsedJson = JsonConverter.ParseJson(response)
FetchDomainInfo = parsedJson
End Function
Sub ProcessDomains()
Dim cellValue As String
For Each cellValue In Range("A2:A50")
If Not IsEmpty(cellValue.Value) Then
Range("B" & Rows.Count).End(xlUp).Offset(1, 0) = FetchDomainInfo(cellValue.Value)
End If
Next cellValue
End Sub
Any suggestions on what might be going wrong with my API request setup?