Forums

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

JQL query not returning results in script

Could BeLoved
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 4, 2022

Hi All,

Trying to use the following script to download attachment by using specific jql query. The query works using jira on the cloud, but not through the script.
It only works if i minimize the query to only the project name and leave out the rest.

HOST="XXX"
USER="XXX"
API_TOKEN="XXX"
curl -sL --request POST \
--user "${USER}:${API_TOKEN}" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--url "https://${HOST}/rest/api/2/search" \
--data '{
"jql": "project = ProjectName AND Organizations = "OrgName" and status in ("STATUS1", "STATUS2") "
"startAt": 0,
"maxResults": 30,
"fields": ["attachment"],
"fieldsByKeys": false
}' \
| jq .issues[]?.fields?.attachment[]?.content \
| xargs -I{} sh -c 'curl -L --user $1 --url $2 --output $(date +%s)_$(basename $2)' - "${USER}:${API_TOKEN}" {}



Would also like some input on:
1. how I could output the attachment name based on ticket nr. Currently I'm doing date+basename, but could not figure out which field to use for ticket.
2. Download only specific attachments for example *.zip files only.

1 answer

1 vote
Rafael Costa
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 5, 2022

I think that you would need parse this jql query to URI.

Instead:

project = ProjectName AND Organizations = "OrgName" and status in ("STATUS1", "STATUS2") 

try replace to:

project+%3D+ProjectName+AND+Organizations+%3D+%22OrgName%22+and+status+in+%28%22STATUS1%22%2C+%22STATUS2%22%29

 I used the site https://www.url-encode-decode.com/ to it

Suggest an answer

Log in or Sign up to answer