Forums

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

Create issue via REST API - javascript does not add labels

Digit Harris January 21, 2021

Hi all,

I have some code to create a JIRA ticket via a REST API call. I can create the ticket with mandatory field values successfully, but when I try to add labels, the process complete, with blank values in the labels field. The label field does appear on the create screen, FYI.

This is the line I'm using:
"labels": ["BTS","lhf"]

Do you know why the labels are not getting created when the ticket is created?

Thanks for the advice!

1 answer

0 votes
Hana Kučerová
Community Champion
January 21, 2021

Hi @Digit Harris ,

welcome to the Atlassian Community!

The label field needs to be on the create screen. Please, try to add it and test again. Thank you.

Digit Harris January 21, 2021

Hi Hana! 

Thanks for the welcome!

The label field does already exist on the create screen.

Hana Kučerová
Community Champion
January 21, 2021

@Digit Harris 

Oh, I'm very sorry. I read your description as "The label field does NOT appear on the create screen".

Labels field is optional, right?

According to documentation this

 "labels": [ "bugfix", "blitz_test" ],

seems ok :-).

But I will try it myself during the day and let you know.

Hana Kučerová
Community Champion
January 22, 2021

Hi @Digit Harris ,

I've just tested creating issue with labels and it worked for me. Those were my test payloads (xxx needs to be replaced by valid account id):

V2:

{
"update": {},
"fields": {
"summary": "My test issue",
"issuetype": {
"id": "10002"
},
"project": {
"id": "10000"
},
"description": "My test description",
"reporter": {
"id": "xxx"
},
"priority": {
"id": "3"
},
"labels": [
"bugfix",
"blitz_test"
],
"assignee": {
"id": "xxx"
}
}
}

V3:

{
"update": {},
"fields": {
"summary": "My test issue",
"issuetype": {
"id": "10002"
},
"project": {
"id": "10000"
},
"description": {
"type": "doc",
"version": 1,
"content": [{
"type": "paragraph",
"content": [{
"text": "My test description",
"type": "text"
}]
}]
},
"reporter": {
"id": "xxx"
},
"priority": {
"id": "3"
},
"labels": [
"bugfix",
"blitz_test"
],
"assignee": {
"id": "xxx"
}
}
}
Like ankeeta likes this
Hana Kučerová
Community Champion
January 22, 2021

To be honest, I'm out of ideas, where the problem could be. I even tried to play with the issue layout, but the field is always filled.

Did you try to create issue with labels in another project to determine, whether there's problem only with one project or whether it is something global?

Maybe try to also use some service like RequestBin to get the information, how does the request looks like and if the data for labels field are really sent and correct.

Digit Harris January 25, 2021

Thanks for taking a look at it, Hana. I'll try RequestBin and see if that makes a difference, but I'm not hopeful. I tried using a service in ServiceNow, and it was successful. It just doesn't work when I convert it to javascript. My gut tells me the issue has to do with the fact that the label field is an array, because I can get all other fields to populate correctly.

Hana Kučerová
Community Champion
January 25, 2021

Hi @Digit Harris ,

when I try to send some invalid data for the labels field, I get error message: "data was not an array"

So if you are able to create the issue, but labels are not there, it seems to me there are only two possibilities:

  • provided array is empty like:
"labels": [],
  •  there is no labels data in the request at all

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events