Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

C# Method Not Allowed using POST creating issue, why? Edited

I've been trying to figure this out for several days, trying every possible combination of JSON string I could find, still will not work.  I am trying to create a new issue in my service  desk project, I keep getting:

" System.Net.WebException: The remote server returned an error: (405) Method Not Allowed.
at System.Net.HttpWebRequest.GetResponse() "

My authentication is working fine, it just seems like I can't create an issue., my guess is a malformed json string format but I have literally copied/pasted many solutions (changing the project key ofcourse) and it's not working.  What am I doing wrong?

I am using visual studio with C# with Jira Cloud instance

string stringData = @"{""fields"": {""project"":{""key"": ""KEYHERE""},""summary"": ""REST ye merry gentlemen."",""description"": ""Creating of an issue using project keys and issue type names using the REST API"",""issuetype"": {""name"": ""Ticket""}}}";


string url = @"http://HOST.atlassian.net/rest/api/2/issue";


var data = Encoding.ASCII.GetBytes(stringData); // or UTF8

WebRequest wrUrl = WebRequest.Create(url);
wrUrl.ContentType = "application/json";
wrUrl.Method = "POST";
wrUrl.Headers["Authorization"] = "Basic " + Convert
.ToBase64String(Encoding.ASCII.GetBytes(SharepointUsername+":"+JiraAPIString));
wrUrl.ContentLength = data.Length;

var newStream = wrUrl.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();

Stream stream = wrUrl.GetResponse().GetResponseStream();

3 answers

1 accepted

I know this is probably long past when you needed it, but I wanted to post a working example:

public JiraDataAccess(string appName, string url, string username, string password)
{
_applicationName = appName;
_userName = username;
_password = password;
var settings = new JiraRestClientSettings()
{
EnableRequestTrace = true
};
jira = Jira.CreateRestClient(url, username, password, settings);

}

protected void btnSubmit_Click(object sender, EventArgs e)
{
using (Logger logger = new Logger())
{
try
{
using (JiraDataAccess jda = new JiraDataAccess(_appName, _url, _username, _password))
{
IssuePriority ip = new IssuePriority("3");

foreach (RepeaterItem item in rpProducts.Items)
{
CheckBox bhkBox = item.FindControl("chkSelect") as CheckBox;
if(bhkBox.Checked)
{
Label lblSystemName = item.FindControl("lblSystemName") as Label;
TextBox tbComments = item.FindControl("txtComments") as TextBox;
TextBox tbMirrorUser = item.FindControl("txtMirrorUser") as TextBox;
HiddenField hidProject = item.FindControl("hidProject") as HiddenField;

string name = "Onboarding";
string summary = String.Concat("New User Access Request: ", lblSystemName.Text, " - ", "User 1");
string description = String.Concat("The following new user access request has been created: ", "System: ", lblSystemName.Text,
"", "Comments: ", tbComments.Text,
"", "Mirror User: ", tbMirrorUser.Text,
"", "Username: ", "blah",
"", "Manager Name: ", "bippity boppity boo");

string reporter = "ctenney";
Task<string> tsk = jda.CreateIssue(hidProject.Value, name, ip, summary, description, reporter);
tsk.Wait();
string caseId = tsk.Result;

}
}
}
}
catch (Exception ex)
{
logger.Error(_appName, "", "btnSubmit_Click", ex);
}
}
}


public async Task<string> CreateIssue(string project, string name, IssuePriority priority, string summary, string description, string reporter)
{
string results = "";
try
{
Issue issue = jira.CreateIssue(project);
issue.Type = name;
//issue.Priority = priority;
issue.Summary = summary;
issue.Reporter = reporter;
issue.Description = description;

await issue.SaveChangesAsync().ConfigureAwait(false);

if (issue.Key != null)
{
if (issue.Key != "")
{
results = issue.Key.Value;
}
}
}
catch (Exception ex)
{
using (Logger logger = new Logger())
{
logger.Error(_applicationName, ex);
}
return null;
}

return results;
}

Hi @Corey Tenney , Its a really nice work.

 

0 votes
Timothy Community Leader Jul 06, 2018

Right, but every time I look for documentation on POST for jira, all I get are curl examples, and I don't know how to use curl, nor can I figure it out.

https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/

Look at this for example, I am getting a "405" error, and I copied this directly off the documentation in Jira


string stringData = @"{""fields"": {""project"":{""key"": ""SS""},""summary"": ""REST ye merry gentlemen."",""description"": ""Creating of an issue using project keys and issue type names using the REST API"",""issuetype"": {""name"": ""Ticket""}}}";


string url = @"http://HOST.atlassian.net/rest/api/2/issue";


var data = Encoding.ASCII.GetBytes(stringData); // or UTF8

WebRequest wrUrl = WebRequest.Create(url);
wrUrl.ContentType = "application/json";
wrUrl.Method = "POST";
wrUrl.Headers["Authorization"] = "Basic " + Convert
.ToBase64String(Encoding.ASCII.GetBytes(SharepointUsername+":"+JiraAPIString));
wrUrl.ContentLength = data.Length;

var newStream = wrUrl.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();

Stream stream = wrUrl.GetResponse().GetResponseStream();




Why isnt this working?  I am going crazy here.

Timothy Community Leader Jul 07, 2018

Couple things to make sure.

  • That the stringData turns out into a valid JSON
  • The endpoint should be https

The string data is literally copy/pasted from Jira docs and other examples I found online.

Can you stop being so cryptic and actually help me out with an example?

I've tried HTTPS and HTTP, I've literally tried everything.  Can you show me at least 1 working example?  Because I have found ZERO online and it's absolutely maddening.  I have never in my life experienced such difficulty trying to communicate with an API in my life.  I also have another experienced developer trying to work with this and he is having no luck.

Screw jira. It's so bad. Hardly any working example out there.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you