I have created C# application to create issue in JIRA using REST API . I am sending the request with data in URI but instead of getting the response key of created issue , i am getting HTML response to create issue in JIRA .
i Am using following code .
data = @"{ ""fields"": {
""project"":
{ ""key"": ""TSI"" }
,
""summary"": ""Test Ticket"",
""description"": ""Creating an issue using project keys and issue type names using the REST API"",
""issuetype"":
{ ""name"": ""1"" }
,
""assignee"":
{ ""name"": ""sajwagner"" }
,""reporter"":
{ ""name"": ""sajwagner"" }
}
}";
string postUrl = "https://jira-int.lufthansa.com/rest/api/2/";
HttpClient client = new HttpClient();
client.BaseAddress = new System.Uri(postUrl);
byte[] cred = UTF8Encoding.UTF8.GetBytes(m_Username + ":" + m_Password);
//byte[] cred = UTF8Encoding.UTF8.GetBytes("sajwagner:Lh2013");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
System.Net.Http.Formatting.MediaTypeFormatter jsonFormatter = new System.Net.Http.Formatting.JsonMediaTypeFormatter();
//System.Net.Http.HttpContent content = new System.Net.Http.ObjectContent<Issue>(data, jsonFormatter);
var content = new StringContent(data, Encoding.UTF8, "application/json");
//HttpContent content = new ObjectContent<string>(data, jsonFormatter);
HttpResponseMessage response = client.PostAsync("/secure/CreateIssueDetails!init.jspa?pid=11080&issuetype=1&summary=Test Ticket&description=Creating an issue using project keys and issue type names using the REST API&reporter=sajwagner&assignee=sajwagner", content).Result;
if (response.IsSuccessStatusCode)
{ string result = response.Content.ReadAsStringAsync().Result; Console.WriteLine(result); }
hello Cedric ,
Issue is sorted now . It was syntax error in DATA field . It should be like ..
data = @"{""fields"":{""project"":{""key"":""TSI""},""summary"":""REST EXAMPLE"",""description"":""Creating an issue via REST API"",""issuetype"":{""name"":""Bug""},""assignee"":{""name"":""sajwagner""},""reporter"":{""name"":""sajwagner""}}}";
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you keep posting your comments as answers, you’re going to confuse people. If you’re directly responding an answer, make it a comment, not a new answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That’s just part of the response from the server. When you’re debugging client-server interactions, you should examine the entire contents of the responses. That includes the body, which in this case should tell you more about the problems you are having.
Take a look at the body of the response, and see if it tells you anything.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If i use following code ..
data = @"{""fields"":{""project"":{""key"":""TSI""},""summary"":{""name"":""REST EXAMPLE""},""description"":{""name"":""Creating an issue via REST API""},""issuetype"":{""name"":""Bug""},""assignee"":{""name"":""sajwagner""},""reporter"":{""name"":""sajwagner""}}}";
string postUrl = "https://jira-int.lufthansa.com/rest/api/2/";
HttpClient client = new HttpClient();
client.BaseAddress = new System.Uri(postUrl);
byte[] cred = UTF8Encoding.UTF8.GetBytes(m_Username + ":" + m_Password);
//byte[] cred = UTF8Encoding.UTF8.GetBytes("sajwagner:Lh2013");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
System.Net.Http.Formatting.MediaTypeFormatter jsonFormatter = new System.Net.Http.Formatting.JsonMediaTypeFormatter();
//System.Net.Http.HttpContent content = new System.Net.Http.ObjectContent<Issue>(data, jsonFormatter);
var content = new StringContent(data, Encoding.UTF8, "application/json");
//var content = new StringContent(data);
//HttpContent content = new ObjectContent<string>(data, jsonFormatter);
//HttpResponseMessage response = client.PostAsync("secure/CreateIssue.jspa?pid=11080&issuetype=1&summary=Test Ticket&description=Creating an issue using project keys and issue type names using the REST API&reporter=sajwagner&assignee=sajwagner", content).Result;
HttpResponseMessage response = client.PostAsync("issue", content).Result;
// HttpResponseMessage response = client.PostAsync("/rest/api/2/issue/createmeta", content).Result;
if (response.IsSuccessStatusCode)
{
string result = response.Content.ReadAsStringAsync().Result;
i am getting error too
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, what error are you getting?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, you’re confused here. You’re mixing up URLs for the REST API and for the human-visible HTML user interface.
The “/secure/CreateIssueDetails!init.jspa” comes from an URL used if you are creating an issue doing the pointy-clicky thing from your web browser.
If you want to use the REST API to create an issue, you need to POST data (formatted as a JSON-string) to “/rest/api/2/issue”. You wouldn’t encode data in as parameters in the URL.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.