I’m trying to connect to a sports data API through RapidAPI using Excel VBA to get real-time football match results. The issue is that VBA isn’t listed as a supported language on their platform.
What I’ve tried so far
I checked their documentation but it mainly shows examples for popular languages like JavaScript and Python. I found this sample code structure they provided:
const config = {
method: 'GET',
endpoint: SERVICE_ENDPOINT,
headers: {
'authorization': 'no-cache',
'accept': 'application/json',
'X-RapidAPI-Token': MY_TOKEN,
'custom-header': 'custom-value'
},
params: {
query1: 'value-1'
}
};
fetch(config).then(function (err, res, data) {
if (err) console.error(err);
console.log(data);
});
What I need
I’m wondering if there’s a way to access the JSON data directly through a web browser URL, or if anyone has experience setting up a simple local server that could act as a bridge between RapidAPI and Excel. Any suggestions would be really helpful.
The browser URL approach won’t work since RapidAPI requires authentication headers that browsers can’t send directly. However, you can definitely make this work in VBA using the WinHttp.WinHttpRequest object instead of XMLHTTP. I’ve found WinHttp more reliable for API calls with custom headers. You’ll need to translate that JavaScript config into VBA by setting the request method to GET, adding each header with SetRequestHeader method, and building your query parameters into the URL string. The main gotcha is handling the JSON response properly - you might want to reference the Microsoft Scripting Runtime library to parse the returned JSON data effectively.
u can totally use xmlhttp request in vba to make the call. just set the headers like in js example. ive had good results doing that with other apis too. important to get that X-RapidAPI-Token right tho, it makes a diff
Actually ran into this exact scenario last year when pulling weather data from RapidAPI into Excel. The key thing that worked for me was using the MSXML2.ServerXMLHTTP.6.0 object rather than the standard XMLHTTP - it handles the authentication much better. You’ll want to create the object, set your method to GET, then add your headers one by one using setRequestHeader. The X-RapidAPI-Key header is crucial and needs to match exactly what’s in your RapidAPI dashboard. For the JSON parsing part, I ended up using a simple text manipulation approach since Excel’s built-in JSON support is limited. Split the response by commas and extract the values you need with InStr and Mid functions. Works reliably once you get the authentication sorted out.