How to extract a list of labels from an incoming webhook, and add them to a created ticket?
Asked by Graeme Baker:

Hey everyone, I've got 2 instances of Jira and I'm using the Send Web Request automation action to post to the other, where I have an Incoming Webhook setup to parse the issue data, and create a ticket in the 2nd instance.

I want to then have them somewhat in sync, so I'm writing the trigger issues key to a custom field, then using another pair or Request/Webhooks to write the new issues key back to the 1st instance ticket in a similar custom field there. Then I can use that as a smart value on the webhook URL to target specific tickets.

I have tried for the life of me to work out how to take {{webhook.Data.fields.labels}} and turn it into a list in some way to then add to the new ticket, without ending up with either an amalgamated mega-label, or an error because of whitespace.

The goal is that the 2nd instance should always match whatever happens to the 1st instances ticket. So if it has 5 labels, so should the 2nd ticket. If I remove one from the 1t ticket, it should get removed from the 2nd.

Any ideas? I feel like I'm probably going about this wrong.


Answers:
author: Bill Sheboy
body: Hi [@Graeme Baker](/t5/user/viewprofilepage/user-id/4758662)

First thing, are you using Jira Cloud? If so I recommend reading this article announcing a change to the packaging / licensing model for automation rules. Unless you are on the Premium or Enterprise level license I suspect the rules you describe will be impacted and have cost implications for synching the instances.

<https://community.atlassian.com/t5/Automation-articles/Introducing-our-new-packaging-model-for-Jira-Cloud-Automation/ba-p/2446099>

Back to your question...

Please review the layout / contents of that webhook data, and then try split the label field using the split() function. That will give you a list of values that then could be iterated over to add them. I recommend doing this in one step, either with a single field edit or using advanced edit with JSON; otherwise multiple edits could cause problems in the rule.

Kind regards,  
Bill

comments: author: Graeme Baker
body: Thanks Bill! We're on data center LTS for both instances, so not a worry (yet!)

I can use the split function to turn the labels into an array after the data has been received, but on 9.4.5, it won't let me use this as a smart value in the Edit Issue/Labels section

When logging **{{webhookData.fields.labels.split(" ")}}**, this returned the array as expected.

Is there a way to do this as a single field edit, or do I need to work out how to iterate over this in the Advanced edit and construct the JSON? I've been trying to research, as I'm fairly green with advanced editing, but no luck so far.

![jira.png](https://community.atlassian.com/t5/image/serverpage/image-id/283889i8DC2927FC8815809/image-size/large?v=v2&px=999 "jira.png")


author: Graeme Baker
body: I got almost there. I tried the following, after reading this <https://community.atlassian.com/t5/Marketplace-Apps-Integrations/How-to-copy-multi-value-field-in-using-Advance-Options-in/qaq-p/769692>:

```
{

    "fields": {

        "labels": {{webhookData.fields.labels.split("_").asJsonStringArray}}

    }

}
```

I get a proper list of labels, but they are all encased in square brackets.


author: Graeme Baker
body: Ah, think I cracked it, no need for the split, with the **.asJsonStringArray**! That seems to do the trick.

I'm sure I'm missing some cases here potentially, around special characters perhaps.

What do you think? This was the final code, as I always want the source issue to be authroative on what the labels should be, and it be a one way sync  

```
{

    "fields": {

        "labels": {{webhookData.fields.labels.asJsonStringArray}}

    }

}
```


author: Bill Sheboy
body: Well done! That was the second approach I was describing.

As you want to synch (not incrementally add / remove) labels, this should work. And as this is going from the Labels field as a source, I do not believe you need handling for special characters.


author: Graeme Baker
body: Thanks Bill. I might try to work out how to sync back and forth later, but this solves the problem I have today :)