Excel VBA - CURL - PUT - JSON - WinHttpRequest

asipoy

New Member
Joined
Jan 12, 2012
Messages
9
I am trying to perform actions on a tool that supports API. I am using Excel VBA ("WinHttp.WinHttpRequest.5.1").


Code:
    https://{domain}.zendesk.com/api/v2/suspended_tickets/1234567890/recover.json
    
    domain - is the domain name of our company
    1234567890 - dummy suspended ticket number


In the help pages of Zendesk, I found the following information.


**Note:** During recovery, the API sets the requester to the authenticated agent who called the API, not the original requester. This prevents the ticket from being re-suspended after recovery. To preserve the original requester, GET the suspended ticket before recovery and grab the author value.


This clearly says that the author would change and I will have to use the GET method to grab the author value. I have successfully grabed the author value from the ticket information (json file). However, I am not aware, how to send PUT request using the following cURL:


Code:
    curl https://{domain}.zendesk.com/api/v2/suspended_tickets/1234567890/recover.json -X PUT -v -u {email@subdomain.com/token}:{token} -d '{"author": {"id": null, "name": "A customer", "email": "acustomer@example.com"}}' -H "Content-Type: application/json"
    
    domain - is the domain name of our company
    1234567890 - dummy suspended ticket number


-----

Code:
    Breaking the above cURL line so that it is readable
    curl https://{domain}.zendesk.com/api/v2/suspended_tickets/1234567890/recover.json
     -X PUT -v -u {email@subdomain.com/token}:{token} -d
     '{"author": {"id": null, "name": "A customer", "email": "acustomer@example.com"}}'
     -H "Content-Type: application/json"


I have used the following code to fetch (GET) information from the json file:

Code:
    TargetURL = "https://www.mysite.co.uk/app/api/v1/test"
    Set HTTPReq = CreateObject("WinHttp.WinHttpRequest.5.1")
    HTTPReq.Option(4) = 13056
    HTTPReq.Open "PUT", TargetURL, False
    HTTPReq.SetCredentials "user", "password", 0
    HTTPReq.setRequestHeader "Content-Type", "application/json"
    HTTPReq.send ({"author": {"id":null,"name":"FIRSTNAME LASTNAME","email":"name@emailaddress.com"}}) 
    MsgBox (HTTPReq.responseText)


Seeking insightful help from professionals and experts.


Regards....
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,214,940
Messages
6,122,352
Members
449,080
Latest member
Armadillos

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