I keep getting error 400. And as far as I know i have correct code. Here's my code. I'm using C#
URL: http://<company_url>/rest/api/2/issue
public string makeRequest()
{
HttpWebResponse response = null;
//ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
string strResponse = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endPoint);
request.UserAgent = userName; //explicit definition
request.Method = httpMethod.ToString();
request.ClientCertificates = new System.Security.Cryptography.X509Certificates.X509CertificateCollection();
request.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => { return true; };
String authHeader = System.Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes(userName + ":" + userpassWord));
request.Headers.Add("Authorization", "Basic " + authHeader);
if (request.Method == "POST" && postJSON != string.Empty)
{
request.ContentType = "application/json";
using (StreamWriter swJSONPayLoad = new StreamWriter(request.GetRequestStream()))
{
//string temp_json = @"{"fields": {"issueType": {"name": "Task"},"project": {"key": "TA"},"assignee": {"name": "OliverCesumission"},"reporter": {"name": "OliverCesumission"}}}";
swJSONPayLoad.Write(postJSON);
swJSONPayLoad.Close();
}
}
try
{
response = (HttpWebResponse)request.GetResponse();
//Process the reponse stream (it could be JSON, XML, HTML)
using (Stream responseStream = response.GetResponseStream())
{
if (responseStream != null)
{
using (StreamReader reader = new StreamReader(responseStream))
{
strResponse = reader.ReadToEnd();
}
}
}
}
catch (System.Net.WebException ex)
{
strResponse = ex.ToString();
}
finally
{
if (response != null)
{
((IDisposable)response).Dispose();
}
}
return strResponse;
}
HERE IS MY JSON DATA:
{
"fields": {
"project": {
"id": "11518"
},
"issuetype": {
"id": "10203"
},
"summary": "[TA] REST API POST",
"description": "TEST ISSUE ONLY",
"reporter": {
"name": "OliverCesumission"
},
"assignee": {
"name": "OliverCesumission"
}
}
}