FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
01-11-2024 06:16 AM - last edited on 01-15-2024 04:15 PM by CodeShepherd
With MLPI we had a sample Excel spreadsheet talking to an MLC. Is there any chance of someone creating a sample spreadsheet using the REST API to talk to a CtrlX?
01-15-2024 04:03 PM - edited 01-15-2024 04:22 PM
Moved to own topic from "MLPI with ctrlX"
As you can use the REST API via VisualBasic in Microsoft Excel it is still possible to do the same. I shortly created some code to get a web token from our authentication server in a ctrlX COREvirtual:
Option Explicit
Sub GetToken()
Dim strToken As String
Dim objServerRequest As Object
'Request a token via REST
Set objServerRequest = CreateObject("MSXML2.SERVERXMLHTTP")
With objServerRequest
.Open "POST", "https://" + Range("C3").Value + "/identity-manager/api/v1/auth/token"
.SetRequestHeader "Content-Type", "application/json"
.setOption 2, 13056 'SXH_OPTION_IGNORE_SERVER_SSL_CERT_ERROR_FLAGS = 2 ; SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 0x3300
.Send "{""name"":""" + Range("C4").Value + """,""password"":""" + Range("C5").Value + """}"
'waiting for response
While objServerRequest.readyState <> 4
DoEvents
Wend
'Create token from response string
strToken = Mid(.ResponseText, 22)
strToken = Mid(strToken, 1, (InStr(1, strToken, """") - 1))
strToken = "Bearer " + strToken
Debug.Print "SERVERXMLHTTP: " + strToken
End With
End Sub
Afterwards this token can be used for all subsequent request. See "Using REST API of ctrlX CORE".
If there is a need for special functions/features to be used in VBA feel free to ask here or create on your own.