Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Unable to create Jira issue through code but able to create issue through Postman

Edited

I am trying to create an issue using service account in Jira via REST API call with code. When I run the code I am getting below error:

{\"summary\":\"Field 'summary' cannot be set. It is not on the appropriate screen, or unknown.\",\"description\":\"Field 'description' cannot be set. It is not on the appropriate screen, or unknown.\",\"components\":\"Field 'components' cannot be set. It is not on the appropriate screen, or unknown.\",\"customfield_11417\":\"Field 'customfield_11417' cannot be set. It is not on the appropriate screen, or unknown.\"}
Below is the code:
static async Task generateJiraTicket()
{
string jiraUrl = "https://<jira-server-url.com>/rest/api/2/issue/";
string username = "<email>";
string apiToken = "<generated_token>";

// Create JSON payload for the new issue
string issueData = @"
{
""fields"": {
""project"": { ""key"": ""<Key>"" },
""summary"": ""Test Jira Ticket for Forms"",
""description"": ""This is a sample Jira ticket created through code."",
""issuetype"": { ""name"": ""Bug"" },
""components"": [{""name"":""Test"",""value"":""Test value""}]
    },
    ""update"": {
        ""customfield_11417"": [
            {
                ""set"": {
                    ""value"": ""No, not required for Release Notes""
                }
            }
            ]
        } 
}";

using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri(jiraUrl);

client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{apiToken}")));

try
{
// Send a POST request to create the issue

HttpResponseMessage response = await client.PostAsync(jiraUrl, new StringContent(issueData, Encoding.UTF8, "application/json"));

if (response.IsSuccessStatusCode)

string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine("Issue created successfully!");
Console.WriteLine($"Ticket URL: {response.Headers.Location}");
Console.WriteLine($"Response content: {responseBody}");
}
else
{
Console.WriteLine($"Failed to create issue. Status code: {response.StatusCode}");
string errorResponse = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Response content: {errorResponse}");
}
}catch (Exception ex)
{

Console.WriteLine($"Response content: {ex}");
}
}
}
With the same URL, Username, API Token and payload, I am able to create an issue in Postman. Can anyone help on this?

0 answers

Suggest an answer

Log in or Sign up to answer