Mapping the sprint ID to the sprint name via webhook request
Asked by Patrizia Heinzl:

Hello,

I need to map a sprint name -which is matching a specific string value- to its corresponding Id:

1. First, I get all sprints in my board: /jira/rest/agile/1.0/board/boardid/sprint

Example of the webhook body:

{id=163608, self=xxx, state=closed, name=Sprintname1, startDate=xx, endDate=xx, completeDate=xx, activatedDate=xx, originBoardId=boardid, synced=false, autoStartStop=false}, {id=163650, self=xx, state=closed, name=Sprintname2, startDate=xx, endDate=xx, completeDate=xx, activatedDate=xx, originBoardId=boardid, synced=false, autoStartStop=false}

2. Now I'm trying to filter through the webhook body to extract a certain sprint id only. However I'm facing issues with the filtering query.

If I use this query: {{#webhookResponse.body.values}}{{name}}={{id}}, {{/}}

I get following output: Sprintname1=163608, Sprintname2=163650, Sprintname3=163641...

However I need to only print the Id of the Sprint which is matching a certain string value in its name.

e.g Sprintname2 = R44/23:

Output I need: 163650

I tried a few things, but nothing worked so far:

{{#webhookResponse.body.values}}{{#if(name,"R44/23")}}{{id}}{{/}}{{/}}

{{#webhookResponse.body.name}}{{#if("R44/23")}}{{id}}{{/}}{{/}}

{{#webhookResponse.body.values.name}} {{#if("R44/23")}} {{webhookResponse.body.values.id}}{{/}}{{/}}

Does anyone have an idea what could be wrong with above queries?


Answers:
author: Kalyan Sattaluri
body: Hello [@Patrizia Heinzl](/t5/user/viewprofilepage/user-id/5264734)

You are missing equals keyword in your first query.

{{#webhookResponse.body.values}}{{#if(equals(name,"R44/23"))}}{{id}}{{/}}{{/}}

comments: author: Patrizia Heinzl
body: Awesome, thank you so much! I tried a few variants with equals but never got it to work. This one works! Thank you very much!


author: Kalyan Sattaluri
body: Great. I recall your other thread around the same topic.

Just to add, in this case you have hard coded R44/23 for the lookup, so it worked, but if you want to pass a smartvalue / variable in its place, maybe from the trigger issue, it will not work as in the context of the list iteration, smart values / variables dont resolve.

If you need to extract ID based on variable look up, you need to save this webhook response in a variable and use a regex [match](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#match--:~:text=match(),o).*%22)%7D%7D%20%2D%3E%20%5Bo%2C%20o%5D) to extract it.

Hoping I havent confused you and if what I am talking about does not apply, please ignore.


author: Patrizia Heinzl
body: Ah thank you. Yes indeed I just tried a smart value and it does not work


author: Patrizia Heinzl
body: But how do I get the regex match with the id?

So you mean to create a variable out of the original webhook, correct?

And on this webhook use the regex match?


author: Kalyan Sattaluri
body: Are you in Cloud edition or Data Center Edition?


author: Patrizia Heinzl
body: Data center edition. I have the option to create variables.


author: Kalyan Sattaluri
body: Sorry, Regex matching is black magic to me.

But you dont need to save it to a variable, I misspoke earlier. You can operate on the webhook response directly if needed... please see below thread for pointers. There maybe better posts, was just the first hit I found.

<https://community.atlassian.com/t5/Jira-Service-Management/Search-in-Webhook-Response-and-get-a-specific-value-back/qaq-p/2029333>

I think other folks maybe more experts who can help guide such a look up behavior.. so after researching, maybe posting another thread will help.

Reason I asked if DC or Cloud was.. In cloud, Jira has native branching which lets us do this For/Each check and we dont have to iterate manually like you did.. so Cloud would have been straight forward. DC is the tricky one, unfortunately.


author: Patrizia Heinzl
body: Ok, thank you. Seems there is again an issue because I cannot match a smart value with a smart value :-( But thank you for your quick help!


author: Kalyan Sattaluri
body: If you wont mind, I will pitch my "not good" solution again from other thread.

If you were to create a task (for example) and just assign all open sprints to this one task and you cancel this task immediately, so It wont show up in any board view or backlog.. It will solve the problem of making web request call to get sprint IDs.

Because then, In your rule, after your trigger, you can do a lookup with JQL as.. Sprint = "Fix Version". This will return the canceled Task and you immediately have access to that Sprint ID.

Solves the problem without needing to go through complicated web request route,, when you look at the board, this canceled story wont show up so no one will be any wiser.

Of course I know this is the not the right way but an option in back pocket.