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();
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;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Screw jira. It's so bad. Hardly any working example out there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Because /rest/api/2/issue/createmeta is a GET method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Couple things to make sure.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.