I have below VBA Code in MS Access which is giving me Authorization error but when I try the same in POSTMAN, It is working using same data. What am I doing wrong ? Note. This is only problem with PUT method. With Get method where only TOKEN is required and CSRF Token is not needed it will working fine for VBA code. Is there any cookie from CSRF Token needs to be write ?
<code>Public Sub AddUserToGroup(GroupID As String, UserID As String)
Dim xmlhttp As Object
Dim url As String
Dim authToken As String
Dim csrfToken As String
Dim jsonBody As String
Dim responseText As String
Dim strCookie As String
' Initialize variables
url = fetchUrl("groups")
' Get request headers
Set headers = getHeaders("PUT")
' Prepare JSON body
jsonBody = "{""schemas"": [""urn:ietf:params:scim:schemas:core:2.0:Group""], " & _
"""id"": """ & GroupID & """, " & _
"""members"": [ { ""value"": """ & UserID & """, ""type"": ""User"" } ] }"
' Create XMLHTTP object
Set xmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
' Open HTTP request
xmlhttp.Open "PUT", url, False
'Set request headers
xmlhttp.SetRequestHeader "Content-Type", headers("Content-Type")
xmlhttp.SetRequestHeader "x-sap-sac-custom-auth", headers("x-sap-sac-custom-auth")
xmlhttp.SetRequestHeader "x-csrf-token", headers("x-csrf-token")
xmlhttp.SetRequestHeader "Authorization", headers("Authorization")
' Send the request
xmlhttp.Send jsonBody
' Get response
responseText = xmlhttp.responseText
' Display response
MsgBox "Response: " & responseText
' Cleanup
Set xmlhttp = Nothing
End Sub
</code>
<code>Public Sub AddUserToGroup(GroupID As String, UserID As String)
Dim xmlhttp As Object
Dim url As String
Dim authToken As String
Dim csrfToken As String
Dim jsonBody As String
Dim responseText As String
Dim strCookie As String
' Initialize variables
url = fetchUrl("groups")
' Get request headers
Set headers = getHeaders("PUT")
' Prepare JSON body
jsonBody = "{""schemas"": [""urn:ietf:params:scim:schemas:core:2.0:Group""], " & _
"""id"": """ & GroupID & """, " & _
"""members"": [ { ""value"": """ & UserID & """, ""type"": ""User"" } ] }"
' Create XMLHTTP object
Set xmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
' Open HTTP request
xmlhttp.Open "PUT", url, False
'Set request headers
xmlhttp.SetRequestHeader "Content-Type", headers("Content-Type")
xmlhttp.SetRequestHeader "x-sap-sac-custom-auth", headers("x-sap-sac-custom-auth")
xmlhttp.SetRequestHeader "x-csrf-token", headers("x-csrf-token")
xmlhttp.SetRequestHeader "Authorization", headers("Authorization")
' Send the request
xmlhttp.Send jsonBody
' Get response
responseText = xmlhttp.responseText
' Display response
MsgBox "Response: " & responseText
' Cleanup
Set xmlhttp = Nothing
End Sub
</code>
Public Sub AddUserToGroup(GroupID As String, UserID As String)
Dim xmlhttp As Object
Dim url As String
Dim authToken As String
Dim csrfToken As String
Dim jsonBody As String
Dim responseText As String
Dim strCookie As String
' Initialize variables
url = fetchUrl("groups")
' Get request headers
Set headers = getHeaders("PUT")
' Prepare JSON body
jsonBody = "{""schemas"": [""urn:ietf:params:scim:schemas:core:2.0:Group""], " & _
"""id"": """ & GroupID & """, " & _
"""members"": [ { ""value"": """ & UserID & """, ""type"": ""User"" } ] }"
' Create XMLHTTP object
Set xmlhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
' Open HTTP request
xmlhttp.Open "PUT", url, False
'Set request headers
xmlhttp.SetRequestHeader "Content-Type", headers("Content-Type")
xmlhttp.SetRequestHeader "x-sap-sac-custom-auth", headers("x-sap-sac-custom-auth")
xmlhttp.SetRequestHeader "x-csrf-token", headers("x-csrf-token")
xmlhttp.SetRequestHeader "Authorization", headers("Authorization")
' Send the request
xmlhttp.Send jsonBody
' Get response
responseText = xmlhttp.responseText
' Display response
MsgBox "Response: " & responseText
' Cleanup
Set xmlhttp = Nothing
End Sub