Is there a plugin or library that could be used to access restful APIs from excel (probably using macros) and then store the responses somewhere (probably in a sheet).
Pardon the missing sample code. I'm not a VBA programmer.
API stands for Application Programming Interface. API's for VBA imply a set of methods that allow direct interaction with the operating system. System calls can be made by executing procedures defined in DLL files.
To import this on excel go to Data>Get Data>From other Sources> From Web or simply Data>From Web. Paste the API URL on the prompt then click OK. Then select Into Table on the Convert tab. Select the Value of Data then right click>Drill Down.
Calls to external APIs can only be made through the Excel application, not through Power Automate under normal circumstances.
You can use the MSXML library within VBA. Then you can create an XMlHTTP request and do a GET or POST etc. Here's a code sample below. It uses late binding i.e. no need to reference the library first:
Option Explicit Sub Test_LateBinding() Dim objRequest As Object Dim strUrl As String Dim blnAsync As Boolean Dim strResponse As String Set objRequest = CreateObject("MSXML2.XMLHTTP") strUrl = "https://jsonplaceholder.typicode.com/posts/1" blnAsync = True With objRequest .Open "GET", strUrl, blnAsync .SetRequestHeader "Content-Type", "application/json" .Send 'spin wheels whilst waiting for response While objRequest.readyState <> 4 DoEvents Wend strResponse = .ResponseText End With Debug.Print strResponse End Sub
I'm using this testing website - JSONPlaceholder - to call a RESTful API. This is the response:
Note that I found that calls to this website with this method fail if you a) make a synchronous request, or b) use http
not https
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With