Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing Jira in C# returns a "you've found a dead link" page

Itai Tzur
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 16, 2018

I generally use a URL like the following in order to see an item in the Jira backlog:

https://{server name}/jira/secure/RapidBoard.jspa?rapidView=6588&view=planning&selectedIssue=C165889-1670

 

And I use a URL like the following in order to view a specific story:

https://{server name}/jira/browse/C165889-1670

 

Now I want to create a subtask via C#, so I tried the following code:

 

public static async Task<string> CreateSubTask()
{
var client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
using (var reader = new StreamReader(await (await client.PostAsJsonAsync(
"https://{server name}/jira/secure/rest/api/latest/issue/",
new
{
project = new {key = "My Project"},
parent = new {key = "C165889-1670"},
summary = "My Summary",
description = "My Description",
issuetype = new {id = 5}
})).Content.ReadAsStreamAsync()))
return await reader.ReadToEndAsync();
}

 

But when I check the returned string, I find a message like the one in https://jira.atlassian.com/secure/attachment/180809/screenshot-2.png - a dead link page.

Can anyone tell me what I am doing wrong?

 

Thanks in advance,

Itai

1 answer

0 votes
Andy Nguyen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 16, 2018

Hey Itai,

A REST endpoint doesn't include /secure.

Instead of https://{server name}/jira/secure/rest/api/latest/issue, can you try this:

  • https://{server name}/jira/rest/api/latest/issue

Cheers,

Andy

Itai Tzur
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 16, 2018

Hey, Andy. Thanks for the swift response.

 

I already did try it without the "/secure" part, and received the following string instead:

{"errorMessages":["Internal server error"],"errors":{}}

 

(Tried it again now, just to be sure - same result.)

Is this considered a progress? If so, what more is my code missing to make this work?

Do I have to provide the HttpClient object with my Jira username and password or something? If so, how?

Or is it something in the Json object that is not set properly?

 

Thanks,

Itai

Andy Nguyen
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 16, 2018

Hey Itai,

I'm not familiar with C#, so can't comment much on your code. But I'm sure that the URL must be:

  • https://{server name}/jira/rest/api/latest/issue

Important points are:

  1. Method is POST
  2. Content-Type is JSON
  3. You need to supply authentication details

I use cURL, and this is the JSON body that I use:

{
"fields": {
"project": {
"key": "SCRUM"
},
"summary": "creating sub-task",
"issuetype": {
"name": "Sub-task"
},
"parent": {
"key":"SCRUM-1"
}
}
}

Take note that, issue type must be Sub-task type, and Project Key must be the same as the key part of the Parent issue key.

You may want to refer to REST API 7.11.2 | issue-createIssue for more info.

I hope this helps.

Suggest an answer

Log in or Sign up to answer