How do I write tickets to Zendesk API using POST JSON requests in VBA?

nhumensky

New Member
Joined
Apr 12, 2016
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Note: I also posted this in Stack Overflow. Link here.

I am trying to write a ticket to a Zendesk API from Access/Excel using VBA. I keep receiving the following error:

"error":"Unprocessable Entity","message":"server could not parse JSON"

My code is as follows: (replacing my actual Zendesk domain, username, and token with "zendeskdomain", "username", and "token" respectively).

VBA Code:
Dim strURL As String, strParse() As String, jsonStr As String
 Dim hreq As New MSXML2.XMLHTTP60
 Dim tixScript As Object

 strURL = "https://zendeskdomain.zendesk.com/api/v2/tickets.json"
 hreq.Open "POST", strURL, 0, "username/token", "token"

 hreq.setRequestHeader "User-Agent", "Chrome/78.0.3904.108"
 hreq.setRequestHeader "Content-Type", "application/json"
 hreq.setRequestHeader "Accept", "application/json"

 jsonStr = """{""ticket"": {""subject"": ""Testing post requests"", ""requester_id"":393329203772, ""comment"": { ""body"": ""This will work"" }}}"""

 hreq.Send jsonStr

 MsgBox hreq.responseText

I was able to take the same JSON string and create a ticket using the actual Zendesk Developer API. I was also able to make a GET connection to work using the same three request headers used in the POST code above.

I feel like I am missing something simple, but I cannot seem to make it work.

Any help would be greatly appreciated.

Thank you
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Your JSON string is wrong. Do not cover the outer curly braces with double quotes but only strings in the JSON array.
Try:

VBA Code:
jsonStr = "{""ticket"": {""subject"": ""Testing post requests"", ""requester_id"":393329203772, ""comment"": { ""body"": ""This one will work"" }}}"
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top