title: Create Issue Jira REST API (400 Bad Request)
body: <h1>The Problem</h1>
  
  <p>I am trying to create a REST API call using a HttpWebRequest to our in-house Jira server. But somehow I keep getting back a (400) Bad Request error. I have also tried with WebClient and other ways but I just don't seem to find the correct approach. Any suggestions?</p>
  
  <p><strong>URL</strong> is correct</p>
  
  <p><strong>User</strong> is correct</p>
  
  <p><strong>Password</strong> is correct</p>
  
  <p><strong>JSON Data</strong> also correct</p>
  
  <p>There must be another way of accessing the remote server right? I have been searching but not seem to find a solution.</p>
  
  <h1>My Code</h1>
  
  <pre><code>public static void CreateJiraRequest(JiraApiObject.RootObject jiraApiObject)
  {
      string url = "https://jira-test.ch.*********.net/rest/api/latest/issue/";
      string user = "peno.ch";
      string password = "**********";
  
      var request = (HttpWebRequest)WebRequest.Create(url);
      request.Method = "POST";
      request.ContentType = "application/json";
      request.Credentials = new System.Net.NetworkCredential(user, password);
  
      string data = JsonConvert.SerializeObject(jiraApiObject);
  
      using (var webStream = request.GetRequestStream())
      using (var requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII))
      {
          requestWriter.Write(data);
      }
  
      try
      {
          var webResponse = request.GetResponse();
          using (var responseReader = new StreamReader(webResponse.GetResponseStream()))
          {
              string response = responseReader.ReadToEnd();
          }
      }
      catch (Exception ex)
      {
          throw ex;
      }
  }
  </code></pre>
  
  <h1>JSON</h1>
  
  <pre><code>{
      "fields": {
         "project":
         {
            "key": "FOO"
         },
         "summary": "Test the REST API",
         "issuetype": {
            "name": "Task"
         }
     }
  }
  </code></pre>
  
  <h1>Exception</h1>
  
  <p>The exception occurs when entering the try block on <code>request.GetResponse();</code> </p>
  
  <p><strong>Additional information</strong>: The remote server returned an error: (400) Bad Request.</p>
  
  <p>Visit the Jira Wiki <a href="https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/" rel="nofollow noreferrer">here</a></p>