POST using VBA when trying to send a JSON to the API returns empty

110 Views Asked by At

I need to send data from who accessed the worksheet in a Json format to an API, it manages to send it and the API receives the information, but only an empty array comes. I'm trying to use the "WinHttp.WinHttpRequest.5.1" version to perform this action, but without success.

This is the code I'm using:

Sub Show()
    Dim OL As Object, olAllUsers As Object, oExchUser As Object, oentry As Object, myitem As Object
    Dim User As String
    Dim Json As String
    
    Set OL = CreateObject("outlook.application")
    Set olAllUsers = OL.Session.AddressLists.Item("All Users").AddressEntries
    User = OL.Session.CurrentUser.Name
    Set oentry = olAllUsers.Item(User)
    Set oExchUser = oentry.GetExchangeUser()
    
    'API
    
    Json = "{""name"": ""Fulano"", ""email"":" + """" + oExchUser.PrimarySmtpAddress + """" + "}"
    
    
    Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
    Url = "http://example"
    objHTTP.Open "POST", Url, True
    objHTTP.Send Json

End Sub
0

There are 0 best solutions below