Hi Committe,

I am trying to use the below code to create a new project in my jira,

using System.Text;
using System.Net.Http;
using System.Json;
using System.Web.Script.Serialization;

namespace Test
{
class Class1
{
public void Create()
{
string message = "Hai \"!Hello\" ";
string data = "{\"fields\":{\"project\":{\"key\":\"TP\"},\"summary\":\"" + message + "\"}}";
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
client.DefaultRequestHeaders.ExpectContinue = false;
client.Timeout = TimeSpan.FromMinutes(90);
byte[] crdential = UTF8Encoding.UTF8.GetBytes("adminName:adminPassword");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(crdential));
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
System.Net.Http.HttpContent content = new StringContent(data, Encoding.UTF8, "application/json");
try
{
client.PostAsync("http://localhost:8080/rest/api/2/issue",content).ContinueWith(requesTask=>
{
try
{
HttpResponseMessage response = requesTask.Result;
response.EnsureSuccessStatusCode();
response.Content.ReadAsStringAsync().ContinueWith(readTask =>
{
var out1 = readTask.Result;
Console.WriteLine("-----> Name :------- Project Name : ");
});
}
catch (Exception exception)
{
Console.WriteLine(exception.StackTrace.ToString());
Console.ReadLine();
Console.WriteLine(Environment.NewLine + "Name : Project Name : ");
}
});
}
catch (Exception exc)
{
}
}
}
}

It throws the issue like below:

"{\"errorMessages\":[\"Unexpected character ('!' (code 33)): was expecting comma to separate OBJECT entries\\n at [Source: org.apache.catalina.connector.CoyoteInputStream@1ac4eeea; line: 1, column: 52]\"]}"

But i use the same json file in Firefox Poster , i have created the issue.

Json file : {"fields":{"project":{"key":"TP"},"summary":"Hai \"!Hello\" "}}"

1 answer

Hi,

I am also used the issue type value, please refer the Json file

{"fields":{"project":{"key":"TP"},"summary":"Hai \"!Hello\" ","issuetype":{"name": "Bug"}}}"

In FireFox poster create the new issue in Jira, but through the given code issue is not created.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,301 views 14 20
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot