XelaIrodavlas
Registered User.
- Local time
- Today, 09:04
- Joined
- Oct 26, 2012
- Messages
- 175
Hello,
Sorry if this is a silly question. I am learning how to write API requests in VBA and have gotten quite far: the request sends and returns a correct response. eg:
<?xml version='1.0' encoding='UTF-8'?><LoginResultData><token>sfbwjvfbjskdfsSomeTokenJhGiiJ.ylH5T5z3yi2kj</token><ttl>3600000</ttl><units>milliseconds</units></LoginResultData>
My question is, how do I interegate that response? I want to take the resulting "token" value and set it to a variable for later use.
This is my code so far:
Thanks all
Sorry if this is a silly question. I am learning how to write API requests in VBA and have gotten quite far: the request sends and returns a correct response. eg:
<?xml version='1.0' encoding='UTF-8'?><LoginResultData><token>sfbwjvfbjskdfsSomeTokenJhGiiJ.ylH5T5z3yi2kj</token><ttl>3600000</ttl><units>milliseconds</units></LoginResultData>
My question is, how do I interegate that response? I want to take the resulting "token" value and set it to a variable for later use.
This is my code so far:
Code:
Sub GetKronosKey()
Dim myHTTP As New MSXML2.XMLHTTP60
Dim myDom As New MSXML2.DOMDocument60
Dim myXML As String
Dim myServer As String
'Create Body
myXML = "<?xml version='1.0' encoding='UTF-8'?><login_request><credentials><username>MyName</username><password>MyPassword</password><company>MyCompID</company></credentials></login_request>"
'Load body
myDom.loadXML (myXML)
'Enter URL
myServer = "https://secure.workforceready.eu/ta/rest/v1/login"
'Set type of API Request (Get, Post etc)
myHTTP.Open "POST", myServer, False
'Set headers
myHTTP.setRequestHeader "API-Key", "MyCompAPIKey"
myHTTP.setRequestHeader "Accept", "text/xml" '"application/json"
myHTTP.setRequestHeader "Content-Type", "application/xml"
'Send Request
myHTTP.send (myDom.XML)
'Do stuff with response
Debug.Print myHTTP.responseText 'This works great and I can see the token within the immediate window, but it's wrapped in other text
'Extract value of token:
'#### This part doesnt work, how do???
'GetKronosKey = myHTTP.token.value
End Sub
Thanks all