Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9022165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:26:12+00:00 2026-06-16T05:26:12+00:00

I have read one answer on atlassian https://answers.atlassian.com/questions/79902/using-httpclient-c-to-create-a-jira-issue-via-rest-generates-bad-request-response where one user created a JIRA

  • 0

I have read one answer on atlassian https://answers.atlassian.com/questions/79902/using-httpclient-c-to-create-a-jira-issue-via-rest-generates-bad-request-response 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 ObjectContent

Http.HttpContent content = new Http.ObjectContent<Issue>(data, jsonFormatter);

The compiler wont accept it. Does anybody know why?

 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<Issue>(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();
            }

And using

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; }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:26:13+00:00Added an answer on June 16, 2026 at 5:26 am

    EDIT

    The message clearly says that System.Net.Http.ObjectContent() expects an Issue object for its first parameter. I expect there is another message right after that saying that there is no conversion possible from a string to an Issue.

    You are passing a string to a method that expects an Issue object. The formatter is used to convert an Issue object to a Json string.

    You already have the string, so there is no point in trying to convert it. You only need the formatter if you have an Issue instance which you want to convert to a Json string. You can use the StringContent class and use its Headers property to add any headers not already set on the client, eg:

    var content=new StringContent(data);
    

    Original

    What is the error message and what kind of project are you using? The System.Net.Http.Formatting namespace is part of ASP.NET Web API. Are you building an ASP.NET application, a console application, something else?

    Unless you ARE building an ASP.NET site this code won’t work. If your only issue is how to parse Json requests, just use another Json deserialization class. Json.NET is a very popular choice.

    In any case there is no reason to use a Json class to convert a string to an HttpContent object containing that exact same string. You can use the StringContent class and use its Headers property to add any headers not already set on the client.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have read in more then one place that using NHibernate's Identifier as Primary
I have read many answers to questions about dynamically resizing NSWindows and nothing has
I have read thru a number of other questions similar to this one -
I'm using Delphi XE2 with FireMonkey. I have read many other questions about MD5
After I have read the answer for this question I have found that using
I have read many answers here but none did answer my exact question. I
I have read Django - CSRF verification failed and several questions (and answers) related
I have read somewhere one of the main differences between Java and C++/C# is
I am working with WCF .NET 3.5 SP1 and have read that one does
I have read a file into a String. The file contains various names, one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.