PrashanthKumar123
New Member
- Joined
- May 1, 2021
- Messages
- 38
Hi - I am looking to call an API from VBA. The response is a JSON object. Using .responsetext, I am able to extract contents, but I presume this converts into a text string. Is there a better way to access items inside the object?
My code as below:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function API_call(i As String) As Object
Url = "https://api.brandsome.io/search?q=" & i
Set API_call = CreateObject("MSXML2.serverXMLHTTP")
API_call.Open "GET", Url, False
API_call.send
API_call_brandname = API_call.responsetext
Debug.Print API_call_brandname
End Function
'Calling the function
Sub test()
Dim i As String
i = "Swiggy"
API_call (i)
End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
JSON response to above example
{"status":true,"data":{"_id":"60a2dad9db064721c0da6e71","brand_name":"Swiggy","brand_domain":"swiggy.com","brand_logo":"https://play-lh.googleusercontent.c...1FrMdrg8jooV9ftDidkOhnKNWacfPhjKae1IA=s180-rw"}}
My code as below:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function API_call(i As String) As Object
Url = "https://api.brandsome.io/search?q=" & i
Set API_call = CreateObject("MSXML2.serverXMLHTTP")
API_call.Open "GET", Url, False
API_call.send
API_call_brandname = API_call.responsetext
Debug.Print API_call_brandname
End Function
'Calling the function
Sub test()
Dim i As String
i = "Swiggy"
API_call (i)
End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
JSON response to above example
{"status":true,"data":{"_id":"60a2dad9db064721c0da6e71","brand_name":"Swiggy","brand_domain":"swiggy.com","brand_logo":"https://play-lh.googleusercontent.c...1FrMdrg8jooV9ftDidkOhnKNWacfPhjKae1IA=s180-rw"}}