The following script is a Visual Basic Script example on how to use the Admin Interface REST API to get the system status.
Code Block |
---|
|
base_uri = http://server:8080/mcid/api/v1/
user="<my api user>"
pw = "<my api key>"
auth = "Basic " & Base64Encode(user & ":" & pw)
Set http=createObject("MSXML2.ServerXMLHTTP.3.0")
'======= LOGIN ========
endPoint = base_uri & "login"
http.open "GET", endPoint, False
http.setRequestHeader "Content-Type","application/json"
http.setRequestHeader "Authorization", auth
http.send endpoint
If http.Status = 200 Then
msgbox "RESPONSE : " & http.responseText
responseText = http.responseText
arr_response = Split(responseText)
sessionid = arr_response(UBound(arr_response))
Else
msgbox "ERRCODE : " & http.status
End If
WScript.Echo http.status & " " & http.responseText
WScript.Echo sessionid
'======= SYSTEMSTATUS =======
endPoint = base_uri & "systemstatus"
http.open "GET", endPoint, False
http.setRequestHeader "Content-Type","application/json"
http.setRequestHeader "Cookie", "x=y" 'het eerste cookie wordt ignored ??
http.setRequestHeader "Cookie", "JSESSIONID=" & sessionid
http.send endpoint
If http.Status = 200 Then
msgbox "RESPONSE : " & http.responseText
responseText = http.responseText
Else
msgbox "ERRCODE : " & http.status
End If
WScript.Echo http.status & " " & http.responseText
'======= LOGOUT =======
endPoint = base_uri & "logout"
http.open "GET", endPoint, False
http.setRequestHeader "Content-Type","application/json"
http.setRequestHeader "Cookie", "x=y" 'het eerste cookie wordt ignored ??
http.setRequestHeader "Cookie", "JSESSIONID=" & sessionid
http.send endpoint
If http.Status = 200 Then
msgbox "RESPONSE : " & http.responseText
responseText = http.responseText
Else
msgbox "ERRCODE : " & http.status
End If
WScript.Echo http.status & " " & http.responseText
'Base64 Encoding Helper Function
Function Base64Encode(sText)
Dim oXML, oNode
Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
Set oNode = oXML.CreateElement("base64")
oNode.dataType = "bin.base64"
oNode.nodeTypedValue =Stream_StringToBinary(sText)
Base64Encode = oNode.text
Set oNode = Nothing
Set oXML = Nothing
End Function
'Base64 Decoding Helper Function
Function Base64Decode(ByVal vCode)
Dim oXML, oNode
Set oXML = CreateObject("Msxml2.DOMDocument.3.0")
Set oNode = oXML.CreateElement("base64")
oNode.dataType = "bin.base64"
oNode.text = vCode
Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue)
Set oNode = Nothing
Set oXML = Nothing
End Function
'Stream_StringToBinary Function
'2003 Antonin Foller, http://www.motobit.com
'Text - string parameter To convert To binary data
Function Stream_StringToBinary(Text)
Const adTypeText = 2
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream 'As New Stream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save text/string data.
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
BinaryStream.CharSet = "us-ascii"
'Open the stream And write text/string data To the object
BinaryStream.Open
BinaryStream.WriteText Text
'Change stream type To binary
BinaryStream.Position = 0
BinaryStream.Type = adTypeBinary
'Ignore first two bytes - sign of
BinaryStream.Position = 0
'Open the stream And get binary data from the object
Stream_StringToBinary = BinaryStream.Read
Set BinaryStream = Nothing
End Function
'Stream_BinaryToString Function
'2003 Antonin Foller, http://www.motobit.com
'Binary - VT_UI1 | VT_ARRAY data To convert To a string
Function Stream_BinaryToString(Binary)
Const adTypeText = 2
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream 'As New Stream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save binary data.
BinaryStream.Type = adTypeBinary
'Open the stream And write binary data To the object
BinaryStream.Open
BinaryStream.Write Binary
'Change stream type To text/string
BinaryStream.Position = 0
BinaryStream.Type = adTypeText
'Specify charset For the output text (unicode) data.
BinaryStream.CharSet = "us-ascii"
'Open the stream And get text/string data from the object
Stream_BinaryToString = BinaryStream.ReadText
Set BinaryStream = Nothing
End Function |