hlh3406
hlh3406

Reputation: 1400

JIRA Rest API 405 rejection C#

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();
        }
    }
}

Upvotes: 0

Views: 276

Answers (1)

Alberto Estrella
Alberto Estrella

Reputation: 671

Looking at your code, here is what I've found:

  • Change the postUrl variable value to https://url.com/rest/api/2/issue.
  • Change the requestUri parameter in the client.PostAsync call to createmeta.

Upvotes: 2

Related Questions