(400) Bad Request submit issue in JIRA

I'm trying to submit an issue using JIRA API with c# and i'm receiving

The remote server returned an error: (400) Bad Request.

JiraManager manager = newJiraManager("uname", "mypass");
manager.SubmitIssue();
 
publicclassJiraManager
 {
privateconststring m_BaseUrl = "https://insightsoftwaresolutions.atlassian.net/rest/api/2/";
        privatestring m_Username;
        privatestring m_Password;
 
        public JiraManager(string username, string password)
        {
            m_Username = username;
            m_Password = password;
        }
 
publicvoid SubmitIssue()
        {
           
            string data=@"{""fields"":{""project"":{""key"":""TES""},""summary"":""Summ"",""description"":""testinggg"",""issuetype"":{""name"":""Bug""}}}";
 
            string result = RunQuery("issue", data: data, method: "POST");
        }

 

protectedstring RunQuery(string resource,string argument = null,string data = null,string method = "GET")
        {
            string url = string.Format("{0}{1}/", m_BaseUrl, resource.ToString());
 
            if (argument != null)
            {
                url = string.Format("{0}{1}/", url, argument);
            }
 
            HttpWebRequest request = WebRequest.Create(url) asHttpWebRequest;
            request.ContentType = "application/json";
            request.Method = method;
 
            if (data != null)
            {
                using (StreamWriter writer = newStreamWriter(request.GetRequestStream()))
                {
                    writer.Write(data);
                }
            }
 
            string base64Credentials = GetEncodedCredentials();
            request.Headers.Add("Authorization", "Basic " + base64Credentials);
 
            HttpWebResponse response = request.GetResponse() asHttpWebResponse;
 
            string result = string.Empty;
            using (StreamReader reader = newStreamReader(response.GetResponseStream()))
            {
                result = reader.ReadToEnd();
            }
 
            return result;
        }
 
        privatestring GetEncodedCredentials()
        {
            string mergedCredentials = string.Format("{0}:{1}", m_Username, m_Password);
            byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
            returnConvert.ToBase64String(byteCredentials);
        }

 

}

2 answers

you have to use URL as like this

https://insightsoftwaresolutions.atlassian.net/rest/api/2/issue

check this

https://docs.atlassian.com/jira/REST/latest/#d2e865

i have already done that. inside my RunQuery() method i'm appending that "issue" part to the base URL

yes i know that, did you noticed diffrenced between your url and my url?

you used rest api as "rest/api/2/" but it is not valid, you have to use like this "rest/api/2/issue"

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,080 views 13 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot