Hi,
I am trying to create issue using C# but getting this error:
StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.NSUrlSessionHandler+NSUrlSessionDataTaskStreamContent, Headers:
{
nel: {"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to": "endpoint-1"}
Server: AtlassianEdge
x-arequestid: bc94f0055967bc138de24fb5824e9bab
x-aaccountid: 63d6e1b6491b20ef64b76545
X-XSS-Protection: 1; mode=block
timing-allow-origin: *
atl-traceid: 883e1d9ad4a71061
Cache-Control: no-cache, no-store, no-transform
Date: Wed, 31 May 2023 19:17:44 GMT
report-to: {"endpoints": [{"url": "https://dz8aopenkvv6s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Content-Type-Options: nosniff
Set-Cookie: atlassian.xsrf.token=181df472-89ab-44b9-aaa1-c4468df68ef6_5d540690f3339243bbf99a814c759c7c07067a13_lin; Path=/; Domain=softnames.atlassian.net; Version=0; Discard; Secure
Content-Type: application/json;charset=UTF-8
nel: {"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to": "endpoint-1"}
x-arequestid: bc94f0055967bc138de24fb5824e9bab
x-aaccountid: 63d6e1b6491b20ef64b76545
X-XSS-Protection: 1; mode=block
timing-allow-origin: *
atl-traceid: 883e1d9ad4a71061
report-to: {"endpoints": [{"url": "https://dz8aopenkvv6s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Content-Type-Options: nosniff
}
this is my code:
public static async Task CreateJiraIssueWithApiToken()
{
// Jira REST API endpoint for creating an issue
string apiUrl = "https://softnames.atlassian.net/rest/api/3/issue/";
// Jira authentication credentials
string username = "my@domain.com";
string apiToken = "xxxxxxxxx";
// Create the JSON payload for the issue
string payload = @{
""fields"": {
""project"": {
""key"": ""MUFFIN""
},
""summary"": ""Test Issue"",
""description"": ""This is a test issue"",
""issuetype"": {
""name"": ""Bug""
}
}
}";
using (HttpClient client = new HttpClient())
{
// Set the API token as the password for basic authentication
string auth = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{apiToken}"));
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", auth);
// Set the request content type to JSON
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
// Send the POST request to create the issue
var response = await client.PostAsync(apiUrl, new StringContent(payload, Encoding.UTF8, "application/json"));
// Check the response status
if (response.IsSuccessStatusCode)
{
// Issue created successfully
Console.WriteLine("Issue created successfully.");
}
else
{
await Clipboard.SetTextAsync(response.ToString());
// Error creating the issue
Console.WriteLine("Failed to create the issue. Error: " + response.StatusCode);
}
}
}