In here I am creating Jira API in C# but it gave me an error when I tried to post string type value inside my string. I think I'm missing a quote. I tried different syntax but it didn't work.
string type = "test";
string data = @"{""fields"":{""project"":{""key"": ""MD""},""summary"":
""Support EXAMPLE"",""description"": ""Testing Support"",""issuetype"":
{""name"": "+ type +" }}}";
string postUrl = "https://aconline.atlassian.net/rest/api/2/issue";
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();client.BaseAddress = new System.Uri(postUrl);
byte[] cred = UTF8Encoding.UTF8.GetBytes("username:password");client.DefaultRequestHeaders.Authorization = new
System.Net.Http.Headers.AuthenticationHeaderValue("Basic",
Convert.ToBase64String(cred));client.DefaultRequestHeaders.Accept.Add(new
System.Net.Http.Headers.MediaTypeWithQualityHeaderValue
("application/json"));
System.Net.Http.Formatting.MediaTypeFormatter jsonFormatter = new
System.Net.Http.Formatting.JsonMediaTypeFormatter();
System.Net.Http.HttpContent content = new
System.Net.Http.StringContent(data,
Encoding.UTF8, "application/json");
System.Net.Http.HttpResponseMessage response = client.PostAsync("issue",
content).Result;
if (response.IsSuccessStatusCode)
{
ViewData["Result"] = "Success! your issue has been posted.";
}
else
{
ViewData["Result"] = response.Content.ReadAsStringAsync().Result;
}
Error:
{"errorMessages":["Unrecognized token 'test': was expecting 'null',
'true',
'false' or NaN\n at [Source:
org.apache.catalina.connector.CoyoteInputStream@41ec44a2; line: 1,
column:
125]"]}