title: How to do a REST api call (PUT method with JSON) in C#?
body: <p>I'm using Jenkins as an continuous integration tool. I'm using the Jira plugin for it so it can update the issues in Jira. But there is something missing there, you can't update the description of the version with it. I decided to do it anyway, using Jira REST api.
  I found a very easy way to do it with curl, in one line :</p>
  
  <pre><code>curl -i -u user:password -H "Content-Type: application/json" -X PUT --data '{"name":"V55"}' http://jira/rest/api/latest/version/10107
  </code></pre>
  
  <p>As you can see, there are 2 parameters I need to get before calling it (the data and the url), and this is where things get complicated. 
  I can get the data with Jenkins easily, the problem is about the url. The version (in the example, 10107) is a string you need to retrieve using a GET request, and then parse the result (it's JSON). Once again, really easy in curl :</p>
  
  <pre><code>curl -i -u user:password -H "Content-Type: application/json" -X GET http://jira/rest/api/latest/project/SBX
  </code></pre>
  
  <p>So basically, what I need is to parse the result to get the version, and then call my PUT.
  And I can't manage to do that. I've tried in ANT, I manage to parse the JSON, but it won't let me call my curl line because of the quotes. I tried with groovy script in ANT, but it fails to load the groovy library. (And I already spent 4 days on it)</p>
  
  <p>Now I want to do it in C# (knowing i'm not familiar with webservices), but every time I find an example of how to do it, something goes wrong. Sometimes it doesn't have authentication, and sometimes visual studio is making jokes.</p>
  
  <p>I followed this tutorial which is really clear: <a href="http://channel9.msdn.com/shows/Endpoint/endpointtv-Screencast-Consuming-REST-services-with-HttpClient/" rel="nofollow">http://channel9.msdn.com/shows/Endpoint/endpointtv-Screencast-Consuming-REST-services-with-HttpClient/</a> but when I replace httpclient.post with httpclient.put, it shows me what it expects as arguments, and when I write the ; to finish the line, VS2012 underlines it in red saying "Microsoft.http.HttpClient" doesn't contain a definition for 'Put'.</p>
  
  <p>TL;DR :</p>
  
  <p>I'm looking for an easy way to implement a PUT request on a REST service with data in JSON. Be it in ANT or in C#. Thanks.</p>
  
  <p>Edit : 
  This is what my code is looking like right now :</p>
  
  <pre><code>            using System;
              using System.Collections.Generic;
              using System.Linq;
              using System.Text;
              using RestSharp;
  
  
              namespace jira_rest_api_test
              {
                  class Program
                  {
                      static void Main(string[] args)
                      {
                          RestClient Client = new RestClient
                          {
                              BaseUrl = "http://jira/rest/api/latest/",
                              Authenticator = new HttpBasicAuthenticator("user", "password")
                          };
                          RestRequest request = new RestRequest("version/10107", Method.PUT);
                          request.AddHeader("Accept", "application/json");
                          request.AddHeader("Content-Type", "application/json; charset=utf-8");
                          request.RequestFormat = DataFormat.Json;
                          request.AddBody("{\"name\":\"v23\"}");
                          var response = Client.Execute(request);
                          Console.WriteLine(request.JsonSerializer.ContentType);
                          Console.WriteLine(request.Resource);
                          Console.WriteLine(request.Parameters.Count);
                          Console.WriteLine(response.Content);
  
                      }
                  }
              }
  </code></pre>
  
  <p>And this is the error I get:</p>
  
  <pre><code>{"errorMessages":["Can not instantiate value of type [simple type, class com.atlassian.jira.rest.v2.issue.version.VersionBean] from JSON String; no single-String constructor/factory method"]}
  </code></pre>