title: Establishing an API session with xmlHttp in VBA
body: <p>I apologize if my question's title is incorrect - I'm used to the idea of PHP sessions with APIs.</p>
  
  <p>I'm trying to accomplish the same feat in VBA with the following code:</p>
  
  <pre><code>'Login
  strLogin = "https://URL.COM/authenticateUser?login=username&amp;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=" &amp; Keyword &amp; "&amp;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
  </code></pre>
  
  <p>With this API, I need to login first prior to executing any calls that will return data.</p>
  
  <p>My problem is that I cannot determine how to "stay logged in" so that my second call works.</p>
  
  <p>after I login, <code>strReturn</code> is populated with the following string: </p>
  
  <pre><code>{"Status":{"Code":"2","Message":"Authentication Succeeded","Success":"true"}}
  </code></pre>
  
  <p>However, when I go to utilize <code>strUrl</code>, I get the following message:</p>
  
  <p><code>{"Status":{"Code":"1","Message":"Invalid User Name Or Password","Success":"false"}}
  </code></p>
  
  <p>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.</p>