title: How to properly call the Jira Rest API
body: <p>I have been trying to set up a function to call the Jira Rest API with parameters to then be able to create an issue in Jira. To call the Rest API Jira provided a documentation which describes how to call the Rest API <a href="https://developer.atlassian.com/server/jira/platform/rest-apis/" rel="nofollow noreferrer">here</a>. On the website, the CURL and the JSON are given. Here is the REST API request I tried to set up in <code>C#</code>:</p>
  
  <pre><code>curl -D- -u peno.ch:yourpassword -H "Content-Type: application/json" --data @foo.json https://jira-test.ch.*******.net/rest/api/latest/issue/
  </code></pre>
  
  <p>This is the foo.json payload:</p>
  
  <pre><code>{
      "fields": {
     "project":
     {
        "key": "FOO"
     },
     "summary": "Test the REST API",
     "issuetype": {
        "name": "Task"
     }
    }
   }
  </code></pre>
  
  <p>I have tried to Implement a <code>HttpWebRequest</code> to call the Rest API and also I have tried with a <code>WebClient</code>. None of them worked. I kind of understand the API but I think I haven't got the parameters right, I think I am doing something wrong there. Also on Google, I didn't find any solution.  </p>
  
  <p>I am getting an Internal error from Jira when executing the function below. (no specific information on the error)</p>
  
  <pre><code>public static void CreateJiraRequest(JiraApiObject jiraApiObject)
  {
      string url = "https://jira-test.ch.*******.net/rest/api/latest/issue/";
      string user = "peno.ch";
      string password = "****";
  
      var client = new WebClient();        
      string data = JsonConvert.SerializeObject(jiraApiObject);
      client.Credentials = new System.Net.NetworkCredential(user, password);
      client.UploadStringTaskAsync(url, data);
  }
  </code></pre>
  
  <p>This is my JiraApiObject which exactly translates to the Json payload shown above.</p>
  
  <pre><code>public class JiraApiObject
  {
      public class Project
      {
          public string key { get; set; }
      }
  
      public class Issuetype
      {
          public string name { get; set; }
      }
  
      public class Fields
      {
          public Project project { get; set; }
          public Issuetype issuetype { get; set; }
          public string summary { get; set; }
      }
  
      public class RootObject
      {
          public Fields fields { get; set; }
      }
  }
  </code></pre>
  
  <p>When I execute the CURL command on the console everything works I just couldn't figure out how to structure the <code>WebClient</code> or <code>HttpWebRequest</code>.</p>
  
  <p>I find that many Jira users face this problem and there is not a single good solution I could find on the internet. I hope to find a solution and help others who have the same problem by raising this question.</p>