Hi,
I am trying to update a version in a project using the REST api via .NET
I can sucessfully do GETs but PUTs and POSTs fail with a '400 bad request' error
Here is the code I am using - the json string has been hard-coded (and copied from the API documentation) until I can get this to work:
var request = WebRequest.Create("http://jira-devt:8080/rest/api/2/version"); request.Method = "POST"; request.ContentType = "application/json"; var json = "{\"description\": \"An excellent version\",\"name\": \"New Version 1\",\"userReleaseDate\": \"5-Jul-2010\",\"project\": \"ADAS\",\"releaseDate\": \"2010-07-05\",\"released\": true,\"archived\": false}"; var writer = new StreamWriter(request.GetRequestStream()); writer.Write(json); writer.Close(); response = request.GetResponse();
Any ideas please?
Thanks
Mark
Here is some code (in case anyone else wants to do this sort of thing :-) ):
var json = "{\"description\": \"An excellent version\",\"name\": \"New Version 1\",\"project\": \"ADAS\",\"releaseDate\": \"2010-07-05\",\"released\": true,\"archived\": false}"; var request = WebRequest.Create("http://jira:8080/rest/api/2/version"); request.Method = "POST"; request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes("admin:JiraAdminPasswordGoesInHere-OtherUsersAreAvailable..."))); // if you need to login request.ContentType = "application/json"; request.GetRequestStream().Write(Encoding.ASCII.GetBytes(json), 0, json.Length); var reader = new StreamReader(request.GetResponse().GetResponseStream()); var jsonResponse = reader.ReadToEnd(); // And if you have defined typed objects you can deserialise using the Newstonsoft.Json library ... var version = JsonConvert.DeserializeObject<Version>(jsonResponse);
Hey all,
It doesn't like both releaseDate and userReleaseDate beging specified at once!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.