Hi All,
I have a macro file which is using API link to import data.
Now I am trying to import the data from same link but not sure where and how to fill the key information.
can anybody help me out.
Below is the macro code which is running successfully.
Sub Button1_Click()
'Create the XmlHttp Object
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
'Set the URL of the API Endpoint
Url = "http://111.345.234.456/unknown_Api/api/DownloadReport/ABC"
objHTTP.Open "GET", Url, False
'Set the API Key
objHTTP.SetRequestHeader "X-XXX-Key", "1234567890"
'Send the API Request
objHTTP.send
'Define an object for holding the API Response
Dim response
'ensure that the call was successful
If objHTTP.readyState = 4 Then
' get the response text
response = objHTTP.responseText
'define a path where the ATT Report should be saved.
Dim strTempPath As String
strTempPath = ThisWorkbook.Worksheets(1).Range("B1").Text
'save response to the above file
Open strTempPath For Binary As #1
Put #1, 1, DecodeBase64(response)
Close #1
MsgBox "Report downloaded to: " & strTempPath
Else
MsgBox "Error: " & objHTTP.Status
End If
End Sub