Forums

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

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

Minori Telang October 27, 2020

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

3 votes
Answer accepted
Kian Stack Mumo Systems
Community Champion
October 27, 2020

Try this syntax!

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

I got that from here.

Minori Telang October 27, 2020

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

Kian Stack Mumo Systems
Community Champion
October 27, 2020

What are the errors?

Minori Telang October 27, 2020

@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"
}
]
}
}

Kian Stack Mumo Systems
Community Champion
October 28, 2020

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

Minori Telang October 28, 2020

@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!

Kian Stack Mumo Systems
Community Champion
October 28, 2020

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

Kian Stack Mumo Systems
Community Champion
October 28, 2020

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.

Kian Stack Mumo Systems
Community Champion
October 28, 2020

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
Minori Telang October 28, 2020

@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.

Minori Telang October 28, 2020

@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!

Kian Stack Mumo Systems
Community Champion
October 28, 2020

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.

Minori Telang October 29, 2020

@Kian Stack Mumo Systems Thanks much!

Suggest an answer

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

Atlassian Community Events