I'm trying to create an issue in my JIRA Server instance using the REST API via C#.
I can retrieve the data fine using REST, but when I try and create I get a 405 error with the Reason Phrase 405 as well.
I've tried the solutions I've found on Google so far, including using https rather than http and I can confirm that my credentials are correct.
I'm really stuck so any help would be great!
Docs: https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/
public string CreateJiraIssue()
{
string data = @"{ ""fields"": {
""project"":
{
""key"": ""TESTREST""
},
""summary"": ""Test Ticket"",
""description"": ""Creating of an issue using project keys and issue type names using the REST API"",
""issuetype"": {""name"": ""Task""}
}
}";
string postUrl = "https://url.com/rest/api/2/issue/createmeta";
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
client.BaseAddress = new System.Uri(postUrl);
byte[] cred = UTF8Encoding.UTF8.GetBytes("username:pwd");
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"));
var content = new StringContent(data, Encoding.UTF8, "application/json");
System.Net.Http.HttpResponseMessage response = client.PostAsync("issue", content).Result;
if (response.IsSuccessStatusCode)
{
string result = response.Content.ReadAsStringAsync().Result;
return result;
}
else
{
return response.StatusCode.ToString();
}
}
}
https://url.com/rest/api/2/issue
(without "/createmeta") as described in the section "Creating an issue using a project key and field names" – Xerillio