title: Creating jira issue via Rest c# httpClient
body: <p>I have read one answer on atlassian <a href="https://answers.atlassian.com/questions/79902/using-httpclient-c-to-create-a-jira-issue-via-rest-generates-bad-request-response" rel="nofollow">https://answers.atlassian.com/questions/79902/using-httpclient-c-to-create-a-jira-issue-via-rest-generates-bad-request-response</a> where one user created a JIRA issue by the following code. I adapted it but get an error by using a self-build class issue with <code>ObjectContent</code></p>
  
  <pre><code>Http.HttpContent content = new Http.ObjectContent&lt;Issue&gt;(data, jsonFormatter);
  </code></pre>
  
  <p>The compiler wont accept it. Does anybody know why?</p>
  
  <pre><code> public string CreateJiraIssue()
          {
  
              string data= @"{ ""fields"": { 
                                  ""project"":
                     {
                         ""key"": ""HELP""
                     },
                                  ""summary"": ""Test Ticket"",
                                  ""description"": ""Creating of an issue using project keys and issue type names using the REST API"",
                                  ""issuetype"": {
                                      ""name"": ""Ticket""
                                  },
                                  ""assignee"": { ""name"": ""user"" }
                              }
              }";
              string postUrl = "https://xxx.jira.com/rest/api/2/";
              System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
              client.BaseAddress = new System.Uri(postUrl);
              byte[] cred = UTF8Encoding.UTF8.GetBytes("username:password");
              client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(cred));
              client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
              System.Net.Http.Formatting.MediaTypeFormatter jsonFormatter = new System.Net.Http.Formatting.JsonMediaTypeFormatter();
  
              System.Net.Http.HttpContent content = new System.Net.Http.ObjectContent&lt;Issue&gt;(data, jsonFormatter);
              System.Net.Http.HttpResponseMessage response = client.PostAsync("issue", content).Result;
              if (response.IsSuccessStatusCode)
              {
                  string result = response.Content.ReadAsStringAsync().Result;
                  return result;
              }
              else
              {
                  return response.StatusCode.ToString();
              }
  </code></pre>
  
  <p>And using </p>
  
  <pre><code>namespace IOnotification_System
  {
      public class Issue
      {
          public Fields fields { get; set; }
          public Issue()
          {
              fields = new Fields();
          }
      }
  
      public class Fields
      {
          public Project project { get; set; }
          public string summary { get; set; }
          public string description { get; set; }
          public Assignee assignee { get; set; }
          public IssueType issuetype { get; set; }
          public Fields()
          {
              project = new Project();
              issuetype = new IssueType();
          }
      }
  
      public class Project
      {
          public string key { get; set; }
      }
  
      public class IssueType
      {
          public string name { get; set; }
      }
       public class Assignee
      {
          public string name { get; set; }
      }
  }
  </code></pre>