I want to close the active session after I executed a few REST API calls (e.g. get the list of cubes).
I'm almost there but it's not working in VBA.
In Postman the similar statements work fine.
I don't think I should provide a Body (I would not know what Body to provide and in Postman there is no Body either), but the code stops at the Send request and the Body.
Code: Select all
Sub LogOut()
Dim sResponse As String
sURL = "http://ccccccc:xxx/api/v1/" & "ActiveSession/tm1.Close"
sUser = "admin"
sPassword = "apple"
sResponse = PostREST(sURL, sUser, sPassword, "")
End Sub
Function PostREST(sURL As String, sUsername As String, sPassword As String, sPOST_Body As String) As String
Dim objHTTP As New MSXML2.XMLHTTP60
With objHTTP
.Open "POST", sURL, False, sUsername, sPassword
.setRequestHeader "Content-Type", "application/json"
.setRequestHeader "Connection", "close"
.send sPOST_Body
If .Status <> "201" Then
MsgBox "Error with query. The URL is" & vbNewLine & vbNewLine & sURL & "The response text is" & vbNewLine & vbNewLine & .responseText
Set objHTTP = Nothing
End
End If
PostREST = CStr(.responseText)
.abort
End With
End Function