I have a bog standard WebAPI that accepts a POST and takes those parameters and processes certain things. I'm not certain if the problem is the VBA or the ASP.Net WebAPI so I am cross posting.

I've used Postman to test the API and it works fine when I post Key/Value params.

I've also tried the following method and relevant parameters and get the same result:

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")

I'm having problems getting it to work with the VBA, when debugging in Visual Studio on the WebAPI I cannot see the values I am posting anywhere. It's like the request is coming in blank. My WebAPI is subsequently throwing an error because the parameters are missing and certain parameters are required.

I'm not sure if this is a problem on the VBA side or the ASP.NET WebAPI side so I am cross posting in a hope someone can highlight or spot what I am doing wrong.

Private Sub Command4_Click()

Dim argumentString As String

argumentString1 = "companyId=228&secondsToLog=15&subject=TestBackup123&description=TestDescription" & _
"&category=&tag=&ticketType=task&assignee=gavin&requesterEmail=bob@smith.com" & _

Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
URL = "http://localhost:64874/api/zendeskhelper"
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
objHTTP.send (argumentString1)

txtresult = objHTTP.responsetext & ": " & argumentString
End Sub

The Web API structure looks like this:

public HttpResponseMessage Post([FromUri] TicketBody ticket)
// Nothing is bound to ticket like it is in Postman

Any help or pointers would be much appreciated!

Related posts

Recent Viewed