Zendesk and RestSharp - PUT

384 views
Skip to first unread message

Hans

unread,
Jul 13, 2012, 6:57:07 PM7/13/12
to rest...@googlegroups.com
Hi

I am trying to update a ticket in Zendesk and would appreciate some help. Reading http://developer.zendesk.com/documentation/rest_api/tickets.html#updating-tickets

I can successfully use curl to do:
 
curl -v -u'user:pass' -H"content-type: application/json" -d '{"ticket": { "priority":"normal","comment":{"value":"Testing 1 2 3 4"

I then try to mimic this in RestSharp. With: 

            var client = new RestClient();
            client.BaseUrl = "https://abc.zendesk.com";
            client.Authenticator = new HttpBasicAuthenticator("user", "pass");

            var request = new RestRequest();
            request.Resource = "/api/v2/tickets/123.json";
            request.Method = Method.PUT;
            request.AddParameter("content-type", "application/json");

            string json = "{\"ticket\": { \"priority\":\"normal\",\"comment\":{\"value\":\"Testing 1 2 3 4 - with RestSharp \" }}}";
            request.AddBody(json);

            IRestResponse response = client.Execute(request);

The ErrorException in response is null.

I know it gets to Zendesk, since when viewing the ticket in their webinterface a nice alert is raised in the browser: "This ticket has been updated since you started viewing it. (ignore this) (reload)". Zendesk support also confirmed that they receive the request, but could not provide further information as to why the priority is not changed or the comment is not updated. So I guess it might be my approach with AddBody that is incorrect ?

Any insights would be appreciated.

BR

Hans

John Sheehan

unread,
Jul 17, 2012, 2:00:08 PM7/17/12
to rest...@googlegroups.com
Try:

var request = new RestRequest();
request.Resource = "/api/v2/tickets/123.json";
request.Method = Method.PUT;
request.DataFormat = DataFormat.Json;
request.AddBody(new { ticket = new { priority = "normal", comment =
new { value = "Testing 1234" } } });

That will automatically set the right Content-Type header and
serialize the object as JSON and write it to the body.

Hans

unread,
Jul 18, 2012, 7:53:08 AM7/18/12
to rest...@googlegroups.com
Thank you John. It works now. Just what I needed !!

BR

Hans
Reply all
Reply to author
Forward
0 new messages