Unable to iterate using WebhookResponse and Advance Branching
Asked by Amish Khatri:

I have a web service that will return data in the form of JSON depicted beow.

I have created a new JIRA Automation Rule that uses "Send Web Request" on Issue transition from "To Do" to "In Progress".

When I use "variterate" to get "WebhookResponses.last.body" I indeed receive data but the problem is the rule doesn't reiterate. I expect to iterate under "For Each" steps in Advance Branching, but instead, it just goes inside once that's it and comes out, though I have 4 test objects in JSON. I am seeking help to fix this issue.

(Figure 1)

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

The below steps "desc- {{variterate.description}}  
- {{variterate.get(0).description}}  
- {{variterate\[0\].description}}  
- {{variterate.0.description}} "

Doesnt print anything after multiple tries.

(Figure 2)

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

Web Service Response :

\[  
{  
"title": "Happy Path - Recurring Payment Setup",  
"description": "User sets up a recurring payment with valid details",  
"expectedResult": "System saves the payment details and sets up the recurring payment successfully"  
},  
{  
"title": "Expected Error - Missing Payment Details",  
"description": "User tries to set up a recurring payment without entering all the required payment details",  
"expectedResult": "System shows an error message about missing payment details"  
},  
{  
"title": "Expected Error - Invalid Payment Details",  
"description": "User enters invalid payment details while setting up a recurring payment",  
"expectedResult": "System shows an error message about invalid payment details"  
},  
{  
"title": "Test Edge Cases - Maximum Recurring Payments",  
"description": "User tries to set up more than the maximum allowed recurring payments",  
"expectedResult": "System rejects the request and shows an error message"  
},  
{  
"title": "Test Edge Cases - Minimum Recurring Payments",  
"description": "User tries to set up the minimum allowed recurring payments",  
"expectedResult": "System saves the payment details and sets up the recurring payment successfully"  
}  
\]


Answers:
author: Bill Sheboy
body: Hi [@Amish Khatri](/t5/user/viewprofilepage/user-id/5422162) ( [@ameesh khatri](/t5/user/viewprofilepage/user-id/3062463) )

It appears you are using two different accounts, so I mentioned both.

Have you confirmed the response body is both valid JSON and the automation rule recognizes it as a list of values?

You can do this with a test, writing this expression to the audit log after the Send Web Request action:

```
the count of items in the body is: {{webResponse.body.size|0}}
```

If the result is not the record count you expect, the body content is not parsing as a list. Instead it is likely plain text, or an array represented as text.

If it is not a list, you may use text functions, such as match() or split() to first parse the body into a list for use in the branch. Once inside of your branch you may use additional text functions to examine the data you believed to be represented as JSON fields. To learn more about those functions, please review this documentation.

* For Jira Cloud: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/>
* For Jira Server / Data Center: <https://confluence.atlassian.com/automation/jira-smart-values-text-fields-993924863.html>

Kind regards,  
Bill

comments: author: ameesh khatri
body: Let me try this [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) to find out whether the return JSON from the service is a list or just a text.


author: Kalyan Sattaluri
body: \<EDIT\> - Below discussion is not valid for this use case because Jira wasnt able to pick [@Amish Khatri](/t5/user/viewprofilepage/user-id/5422162) response was valid JSON. Need to use .match logic as suggested by [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) in such cases.

*** ** * ** ***

Hello [@Amish Khatri](/t5/user/viewprofilepage/user-id/5422162)

Please post the audit log of {{WebhookResponses.body}} so we can understand whats going on.

Cause its unclear if the JSON response you posted, is it output of log action of {{WebhookResponses.last.body}} or what... cause thats what you are logging in in your first screenshot.

So please clarify that first.

My immediate suggestion without knowing above point is, your advanced branch should be {{WebhookResponses.body}} ..

Also, for rules like these, dont directly create/update issues.

First log data every where, including the branch so you can confirm you have the data at hand before updating issues.

Finally just FYI, once inside a branch, you reference fields with dot notation... so {{variterate.description}} to pull out the description.

comments: author: Amish Khatri
body: [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) I tried with {{Webhookresponses.body}}} and was able to print so the response is coming but under advanced branching the "variterate.description" doesn't capture .See the attached screenshots for the reference.


author: Kalyan Sattaluri
body: [@Amish Khatri](/t5/user/viewprofilepage/user-id/5422162)

Sorry, lets start over.

What are you calling in your "send web request"?

And right after you have made the send web request call, can you log {{webResponse.body}} and post the JSON here.


author: Amish Khatri
body: [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) these are screenshots which generated comments on story where you can see "variterate.description" hasn't generated anything. Another screenshot is about response from webhookresponses.body

![jira-rule3.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/306936i5B20CB4374F822A6/image-size/large?v=v2&px=999 "jira-rule3.jpg")![jira-rule4.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/306937iD4CC1724142C5800/image-size/large?v=v2&px=999 "jira-rule4.jpg")


author: Amish Khatri
body: Hello [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) below is the steps to call "send web request" and indeed receive the above JSON output.

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


author: Kalyan Sattaluri
body: [@Amish Khatri](/t5/user/viewprofilepage/user-id/5422162)

Instead of webhookresponses.body try webresponse.body.

So can you... right after "send web request", log {{webresponse.body}} like I have it below and share the JSON.

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


author: Kalyan Sattaluri
body: [@Amish Khatri](/t5/user/viewprofilepage/user-id/5422162)

Make your rule like I have below and share complete audit log. Please pay attention to highlighted steps and dont bother updating comments yet.

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


author: ameesh khatri
body: Below are comment logs received from the automation rule [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) . You can see " desc - " which means, it doesnt print variterate.description however it has printed Webhookresponses.body as "WebhookResponses.body"

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


author: Kalyan Sattaluri
body: [@Amish Khatri](/t5/user/viewprofilepage/user-id/5422162) [@ameesh khatri](/t5/user/viewprofilepage/user-id/3062463)

Did you see my earlier posts and what changes I suggested you do to your rules? Your requirement can be solved simply if you just follow those steps.


author: ameesh khatri
body: [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) tried the way you asked to change but not printing after changing webresponse.body.

![jira-rule2.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/307018i6A00A0970480513A/image-size/large?v=v2&px=999 "jira-rule2.jpg")![jira-rule3.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/307019i87B887A8A458C18E/image-size/large?v=v2&px=999 "jira-rule3.jpg")


author: Kalyan Sattaluri
body: [@Amish Khatri](/t5/user/viewprofilepage/user-id/5422162) [@ameesh khatri](/t5/user/viewprofilepage/user-id/3062463)

I am assuming {{webresponse.body}} gave you the JSON you posted in your first post.

So Unless you post full screenshot of your audit logs, we cannot tell or help.

Just log it like I have it in my screenshot.

So, I cannot engage further unless you post screenshot of your full rule/complete audit log.

Audit log should specifically show {{webresponse.body}} captured before you branch.

And for the love of god, please stop updating comments and posting that screenshot alone. It tells nothing.


author: ameesh khatri
body: Hello [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) , Below is the complete audit log which you requested. I have changed the rule as per your suggestion with {{webresponse.body}} . Though you see the first box of rule in the snap has clipped, but to fit the entire snapshot I did my best to get the entire snapshot. The first step in the rule is the "send web request" only.

Apology, if you find multiple screenshots without comments before, but my machine has some slowness so my previous replies were just screen shots.

Here two snapshots, rule details and audit log respectively. Even after using webresponse.body "variterate.description" doesnt provide any value.

![jira-rule9.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/307179i595CCFA06D71CBAC/image-size/large?v=v2&px=999 "jira-rule9.jpg")![jira-rule8.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/307180iA6E6C132AFE7E9BF/image-size/large?v=v2&px=999 "jira-rule8.jpg")


author: Kalyan Sattaluri
body: [@Amish Khatri](/t5/user/viewprofilepage/user-id/5422162) [@ameesh khatri](/t5/user/viewprofilepage/user-id/3062463)

There is no reason what I suggested should not work.

Even though I have asked you to log both outside and inside the branch, You are NOT logging me details inside the branch and instead putting comments directly in rule.

When you add comments to tickets which have smart values, Audit log currently does not render smart values. So it tells nothing.

And we just keep going back and forth.

**Again** - What I have suggested has been proven to work a thousand plus time by others in this forum. Thats how I have leant and I know it works because I have used the same logic for my rules. Its not something I have invented.

My suggestion is, take a break from this thing. Come back after some time, reread this thread fully \& carefully, especially my last few posts and implement this rule from scratch.


author: ameesh khatri
body: I am facing an issue with the Smart Value not rendering the value [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) when the JSON response contains 3-4 nodes. According to my understanding, variterate should iterate the same number of times as the nodes, but it seems to iterate only once, which is perplexing.

Regarding the audit logs, I sent them to you as requested. However, I'm uncertain about what might be missing since the entire rule audit, both inside and outside the branch, is visible in the screenshot. Is there anything else you would like me to provide?

I am aware that others may have successfully implemented similar solutions. The rule I am using is quite straightforward, and I am puzzled by the ongoing issue over the past 3-4 days.

I have thoroughly reviewed this thread multiple times and have ensured that I provided all the requested information. Nevertheless, I will reevaluate it once again to see if there is anything I might have missed.


author: Kalyan Sattaluri
body: **If my sample JSON is like below, whose structure is exactly just like yours**

\[  
{  
"self": "<https://trainjira002.atlassian.net/rest/api/3/version/10001>",  
"id": "10001",  
"description": "MY DESCRIPTION 4",  
"name": "RELEASE 4",  
"archived": false,  
"released": false,  
"projectId": 10000  
},  
{  
"self": "<https://trainjira002.atlassian.net/rest/api/3/version/10002>",  
"id": "10002",  
"description": "MY DESCRIPTION 3",  
"name": "RELEASE 3",  
"archived": false,  
"released": false,  
"projectId": 10000  
},  
{  
"self": "<https://trainjira002.atlassian.net/rest/api/3/version/10003>",  
"id": "10003",  
"description": "MY DESCRIPTION 2",  
"name": "RELEASE 2",  
"archived": false,  
"released": false,  
"projectId": 10000  
},  
{  
"self": "<https://trainjira002.atlassian.net/rest/api/3/version/10004>",  
"id": "10004",  
"description": "MY DESCRIPTION 1",  
"name": "RELEASE 1",  
"archived": false,  
"released": false,  
"projectId": 10000  
}  
\]

**My rule is like below, (as I have suggested to you):**

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

**Then my audit log is like below: (notice I am logging {{variterate.description}} inside branch so I know value is getting populated)**

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

**My Final Output is like below:**

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

Your JSON structure is no different than what I have.

That is why I asked you to LOG the {{variterate.description}} inside the branch as well, which you dont for some reason.

Maybe post this thread again so others can help cause obviosly I am not able to.


author: ameesh khatri
body: [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) I replicated the way you created the rule and have seen the rule is failing because {{variterate.description}} is getting blank. Absolutely frustrating for me :(

Here are the latest snapshots:

Yesterday when I ran {{webResponse.body.size}} it shows blank as [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) asked to check which means there is definately problem with JSON list like response coming from the service.

If the iteration rule doesnt work I need to check match() or string functions which I have to explore it.

![jira-rule11.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/307449i8915E679BD26C66E/image-size/large?v=v2&px=999 "jira-rule11.jpg")![jira-rule10.jpg](https://community.atlassian.com/t5/image/serverpage/image-id/307450i0FB2AD6465A954EA/image-size/large?v=v2&px=999 "jira-rule10.jpg")


author: Kalyan Sattaluri
body: [@Amish Khatri](/t5/user/viewprofilepage/user-id/5422162) [@ameesh khatri](/t5/user/viewprofilepage/user-id/3062463)

Maybe its those leading and ending square brackets making it JSON array which Jira is not able to parse. I can think of 4 different options of varying complexity.

1. Try to send this web response you have received to an incoming webhook unchanged and see if Jira can parse it. To do this, create a new rule with trigger as incoming webhook, grab the URL and then, in your existing rule, once you have made the web request, send this {{webreponse.body}} in payload to the URL, and finally, in the new rule, check {{webhookData.size}}
2. Same as above, but before making the call to webhook, remove the leading and ending square brackets, like {{webreponse.body.remove("\[").remove("\]")}} because they seem to be the issue. And check if you can parse the JSON.
3. As [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) has suggested, you can parse the text and extract your values. See [HERE](https://community.atlassian.com/t5/Jira-Software-questions/Parsing-a-text-field-with-a-JSON-object/qaq-p/2260884)for example
4. Finally, see if you have another end point which gives same data but in a JSON which Jira can parse.

I would make sure #4 is an option, if not, quickly check #1 \& #2 if they work, if not, you can solve it by #3.


author: ameesh khatri
body: Hello [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) and [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)

The issue is fixed by #3 suggested by [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306) . THANK YOU SO MUCH for your extended help in resolution. Really Appreciated your help on this issue.

I have another problem of increasing "send web request", but I know right now its not feasible in Jira rules to increase timeout, nevertheless will check with web service publisher to optimize web service response time.


author: Kalyan Sattaluri
body: Hello [@Amish Khatri](/t5/user/viewprofilepage/user-id/5422162) [@ameesh khatri](/t5/user/viewprofilepage/user-id/3062463)

Great to hear you got it resolved.

Can you please accept Bill's response as answer cause that was the solution and when you get a chance, post your method for future folks to understand the process to take...


author: Amish Khatri
body: Done ! [@Kalyan Sattaluri](/t5/user/viewprofilepage/user-id/5312306)