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

JIRA C# (.NET) REST 400 response

Ramli August 16, 2013

Hi All,

I am trying to create an issue using the REST service trough C# (.NET). However i can't seem to send a correct json request i use the code below. I read that many developers have this problem could sombody help ?

Thanks in advance.

Vars i use to feed the REST Service

var JiraBaseURL = "https://xxx.atlassian.net/rest/api/2/issue";

 var post_json = "\"fields\": { \"project\": {  \"id\": \"TJI\" }, \"description\": \"Hellow why doesn't this work\", \"summary\": \"REST ye merry gentlemen.\", \"issuetype\": { \"name\": \"Bug\" } } ";

// The code to call the service

string mergedCredentials = string.Format("{0}:{1}", User, Pass);
byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials);
                var Credentials = Convert.ToBase64String(byteCredentials);

                HttpWebRequest request = WebRequest.Create(JiraBaseURL) as HttpWebRequest;
                request.ContentType = "application/json";
                request.Method = "POST";

                if (post_json != null)
                {
                    using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
                    {
                        writer.Write(post_json);
                    }
                }


                request.Headers.Add("Authorization", "Basic " + Credentials);

                HttpWebResponse response = request.GetResponse() as HttpWebResponse;

                string result = string.Empty;
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    result = reader.ReadToEnd();
                    
                }

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Jyotiranjan Rout August 6, 2015

Are you able to get response here (in this line) ? HttpWebResponse response = request.GetResponse() as HttpWebResponse; I'm having problem, its saying unable to connect server? Are you getting this problem? or Its OK and you are getting proper response?

0 votes
Ma Ke November 12, 2013

Bump

TAGS
AUG Leaders

Atlassian Community Events