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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Seeing Error while trying to add labels to JIRA via REST API

Hello,

I am working on Logicmonitor+JIRA integration. I want to add labels to my JIRA ticket and I am using REST API in the JSON format to accomplish this. Currently below is what is configured for labels. 

"labels": [
{"add":"LogicMonitor"},{"remove":"REACTIVE"}
],

But I see following errors, can someone please help:

{"errorMessages":[],"errors":{"labels":"string expected at index 0"}}

 

1 answer

1 accepted

1 vote
Answer accepted

Try this syntax!

{ "update": { "labels": [ {"remove": "newlabel"}, {"add": "Test-label"}] } }

I got that from here.

@Kian Stack Mumo Systems  Thanks! I tried that but it still does not work and throws new erros.

What are the errors?

@Kian Stack Mumo Systems Below is the error:

{"errorMessages":["Unexpected character ('{' (code 123)): was expecting double-quote to start field name\n at [Source: org.apache.catalina.connector.CoyoteInputStream@695d2976; line: 1, column: 344]"]}

Below is how I configured:

{
"fields": {
"project": {
"key": "FOUNENG"
},
"summary": "LM - ##DATASOURCE## ##ALERTTYPE## ##LEVEL## alert ##HOSTNAME##",
"description": "##MESSAGE##",
"issuetype": {
"name": "Task"
},
{ "update": { "labels": [ {"remove": "REACTIVE"}, {"add": "LogicMonitor"}] } },
"components": [
{
"name": "Network"
}
]
}
}

@Minori Telang, are you trying to create a ticket? Or update an existing ticket?

@Kian Stack Mumo Systems I am trying to create a ticket. LogicMonitor is a network monitoring tool, so after the Logicmonitor + JIRA integration whenever there is an alert generated on Logicmonitor it will trigger JIRA to create a new ticket. All this is working fine except the label part. As you can see above "FOUNDENG" is our project name. On JIRA we have setup a rule, if someone opens a ticket with FOUNENG that ticket should populated with label " REACTIVE". As I have recently integrated JIRA+LM, I have added a new rule to the FOUNENG project to add " LogicMonitor" as well when somone opens a ticket. Now, the problem is that I see 2 duplicate tickets getting generated one with the label " LogicMonitor" other one with "REACTIVE". That is the reason, I want to remove this "REACTIVE" from the REST API, so the only one ticket populates and with the label " LogicMonitor".Thanks!

Minori,

I'll take a look at the JSON for you, but where is the second ticket coming from? Your Rest API should only be creating a single ticket, but you make it sound like it is creating two.

 

Thanks,

Kian

Also, you can't "remove" when you are creating it. That doesn't make sense. If anything, your automation rule would need to filter out these specific tickets.

So here is the JSON which will create an issue for you with the label of LogicMonitor

 

{
"fields": {
"project": {
"key": "FOUNENG"
},
"summary": "LM - ##DATASOURCE## ##ALERTTYPE## ##LEVEL## alert ##HOSTNAME##",
"description": "##MESSAGE##",
"issuetype": {
"name": "Task"
},
"labels": ["LogicMonitor"],
"components": [
{
"name": "Network"
}
]
}
}

To address the other issues will require working on your automation rule.

Like Minori Telang likes this

@Kian Stack Mumo Systems Thanks! I already had that JSON configured and was able to see the label logicmonitor but alone with that I could see REACTIVE as well. I thought adding "remove:REACTIVE" might remove that label when Logicmonitor sends a request to JIRA. But, thanks again, this clarifies that it is not the issue with the JSON but the automation rule on JIRA.

@Kian Stack Mumo Systems - Can you please give a brief idea on what changes needs to be done on the JIRA side ? What kind of automation rules need to be set up ? Thanks in advance!

Minori, I don't know what automation rules you have set up, so I can't speak to what kind of changes need to be made.

Typically, when creating automated tickets via REST API (which you are doing) you would use some sort of service account. What I would look to do is set a condition on the automation rule which is setting the label for new tickets to exclude the user account you are leveraging to create those tickets via Json.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you