Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

Establishing an API session with xmlHttp in VBA

$
0
0

I apologize if my question's title is incorrect - I'm used to the idea of PHP sessions with APIs.

I'm trying to accomplish the same feat in VBA with the following code:

'Login
strLogin = "https://URL.COM/authenticateUser?login=username&apiKey=password"
Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xmlHttp.Open "GET", strLogin
xmlHttp.setRequestHeader "Content-Type", "text/xml"
xmlHttp.send

'Save the response to a string
strReturn = xmlHttp.responseText


'Open URL and get JSON data

strUrl = "https://URL.COM/Search/search?searchTerm="& Keyword & "&mode=beginwith"
Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xmlHttp.Open "GET", strUrl
xmlHttp.setRequestHeader "Content-Type", "text/xml"
xmlHttp.send

'Save the response to a string
strReturn = xmlHttp.responseText


Sheets(1).Cells(20, 2).Value = strReturn

With this API, I need to login first prior to executing any calls that will return data.

My problem is that I cannot determine how to "stay logged in" so that my second call works.

after I login, strReturn is populated with the following string:

{"Status":{"Code":"2","Message":"Authentication Succeeded","Success":"true"}}

However, when I go to utilize strUrl, I get the following message:

{"Status":{"Code":"1","Message":"Invalid User Name Or Password","Success":"false"}}

I have used this code in prior projects where I needed to supply an API key along with the URL for each request to the server - so this obviously worked fine. I'm not sure how to achieve the concept of "establishing a session" though with xmlHttp.


Viewing all articles
Browse latest Browse all 88835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>