Jira Automation: Counting Issues with JQL API via Send Web Request
Asked by simonlee:

Hi, I'm using Jira Cloud in a company-managed project and trying to calculate the progress percentage of parent issues based on the status of their child issues in Jira Automation.

Here's what I'm aiming to do:

1. Trigger the rule when a child issue is created, edited, or deleted.
2. Use the trigger to get the parent issue key.
3. If the parent exists, count the child issues using the "Count issues using JQL" API: [Count issues using JQL API](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-search/#api-rest-api-3-search-approximate-count-post).   
   The reason I am using the REST API is that the **Lookup Issues** action in Jira Automation has a limit of 100 issues. I have some initiatives with more than 100 epics, so I need to bypass that limitation.
4. The API works fine when I use **cURL**, and it returns the correct count.
5. However, when I attempt to use this API in Jira Automation, the count value returned is always 0.

Request payload:

```
headers

Accept: Application/JSON
Content-Type: Application/JSON


custom data

{"jql": "project=kdev and parent={{triggerissue.parent.key}}"}

or 

{"jql": "project=kdev"}
```

Response payload:

```
{ "count": 0 } // count is always 0, response status is 200 = success
```

Even though I know there are issues that match the JQL query, the response count is always 0 when used in Jira Automation.

Has anyone successfully implemented this, or can provide guidance on how to get the correct count of child issues through Jira Automation?

Any help would be greatly appreciated!


Answers:
author: Stuart Wosika
body: Take a look at my response (to my own ticket actually :-) ) :

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| <https://community.atlassian.com/t5/Automation-questions/I-want-to-create-a-total-sum-for-a-custom-field-Jira-Data-Center/qaq-p/2809379#M11723> I had a similar issue getting 200 response so the API call was somehow quietly erroring. I resolved this in my case with the header "authorization" adding bearer. This is what I am using for authorisation. Hope this helps. p.s. Have you got {{triggerissue.parent.key}} working in the body of "custom data". |

comments: author: simonlee
body: [@Stuart Wosika](/t5/user/viewprofilepage/user-id/5235433) was right, the **Authorization header** was indeed the source of the problem.

Also, {{triggerissue.parent.key}} is working well. Here is my final custom data for two cases:

```
{"jql": "parent={{triggerIssue.parent.key}}"}
{"jql": "parent={{triggerIssue.parent.key}} and statusCategory=Done"}
```

<br />

One thing I'm curious about is why the response was 200 success. If the issue was related to authentication, shouldn't it have returned a 401 unauthorized instead?


author: Pablo Vergara
body: Thank you [@Stuart Wosika](/t5/user/viewprofilepage/user-id/5235433)! - What an unexpected thing! I imagine no auth token header is required if the rule actor has the proper access to browse the issues involved.

Or, I would expect the Jira Cloud API to respond properly if that authorization is required and not just a 0 count. Do you agree they need to enhance this endpoint? I bet so.

Thanks again for your addition to my response here!

- Pablo


author: Pablo Vergara
body: Hi [@simonlee](/t5/user/viewprofilepage/user-id/5553020)

Welcome to the community!

I was curious about your case and decided to take some tests. Unfortunately, I got the same results when using the /rest/api/2/search/approximate-count API endpoint.

It seems there is a problem when the request is sent through Automation for Jira, so I suspect the Custom data is not correctly sent over as the request's payload, and it always returns 0.

As you can see in the captures below, even when a specific issue key is sent as part of the JQL, the count remains 0. That would be absurd, knowing the issue exists.

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

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

When I try using the JMWE Nunjucks tester (and callJira filter to send the request), the response is OK, and the count is 1, as it should be. This confirms it's something specifically with A4J that's failing.

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

I would suggest opening a bug report with Atlassian. They should check why we have this inconsistency.

I'm afraid there is not much else we can do regarding this behavior.

- Pablo / SSE - ServiceRocket

comments: author: simonlee
body: Thank you so much for the help. The **Authorization header** was the source of the problem.


Tags: automation

cloud

jira-cloud

rest-api