How to update a jira issue summary though the rest api using restsharp
c#-4.0, jira-rest-java-api, restsharp
Solution
I finally found a way to make it work, it's not totally how i expected it or would of liked it to work but it's the only way i found yet. Hopefully this will be useful to someone else
public void SetJiraIssue(string issueKey, JiraIssue j)
{
RestRequest request = new RestRequest("issue/{key}", Method.PUT);
request.AddUrlSegment("key", issueKey);
request.RequestFormat = DataFormat.Json;
string jSonContent = @"{""fields"":{""summary"":""test changing summary""}}";
request.AddParameter("application/json", jSonContent, ParameterType.RequestBody);
var response = Execute(request);
Console.WriteLine(response);
}
Problem
I have been playing around with the jira rest api to eventually replace my soap implementation in a c# app using the 4.0 .net framework. I am also using restsharp. While i had no problem getting an issue or searching for an issue with the rest api, i have been pulling my hairs with updating a jira issue. These are my execute methods, they work fine to do get or search jira issues. Usual error message i get when i call SetJiraIssue is the following {"errorMessages":["one of 'fields' or 'update' required"],"errors":{}}. If i pass a simple JSOn string exeample(string jSonContent = @"{""Fields"":{""summary"":"" testing summary update""}}") to the body of the request, then it complains that there is no constructor for it. Anybody out there as an idea of what i am doing wrong? Comments and suggestion are more then welcome ``` private string Execute(RestRequest request) { var client = new RestClient(_jiraUrl); client.Authenticator = new HttpBasicAuthenticator(_accountId, _password); request.AddParameter("AccountSid", _accountId, ParameterType.UrlSegment); var response = client.Execute(request); if (response.ErrorException != null) { const string message = "Error retrieving response. Check inner details for more info."; var jiraManagerException = new ApplicationException(message, response.ErrorException); throw jiraManagerException; } return response.Content; } /// <summary> /// Executes a jira rest call and retuns the response if any as a business object. /// </summary> /// <typeparam name="T">Type of the return type for deserialization.</typeparam> /// <param name="request">THe reste request.</param> /// <returns></returns> private T Execute<T>(RestRequest request) where T : new() { var client = new RestClient(_jiraUrl); client.Authenticator = new HttpBasicAuthenticator(_accountId, _password); request.AddParameter("AccountSid", _accountId, ParameterType.UrlSegment); var response = client.Execute<T>(request); if (response.ErrorException != null) { const string message = "Error retrieving response. Check inner details for more info."; var jiraManagerException = new ApplicationException(message, response.ErrorException); throw jiraManagerException; } return response.Data; } public void SetJiraIssue(string issueKey, JiraIssue j) { RestRequest request = new RestRequest("issue/{key}", Method.PUT); request.AddUrlSegment("key", issueKey); request.RequestFormat = DataFormat.Json; request.AddHeader("Content-type", "application/json"); j.Summary = "modifiying this issue"; request.AddBody(j); var response = Execute(request); Console.WriteLine(response); } ```