Forums

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

How to use variables in JQL POST Search

James Lester Desipeda
May 3, 2018

I'm trying to make a script to constantly query Jira (using cron) for tickets with its custom field (containing some time information about the ticket) defined as the current time. I have the lines below in my script but it seems like JQL doesn't accept variables:

starttime=$(date +"%H:%M")

(curl \
-u username:password \
-X POST \
-H "Content-Type: application/json" \
--data '{"jql":"project = ZZZ and cf[99999] = \"$starttime\"","startAt":0,"maxResults":5,"fields":["customfield_99999","key"]}' \
"https://jira.url.com/rest/api/2/search"
) | python -m json.tool > /home/tickets.txt

 

The query works if the custom field value is defined but when using a variable it doesn't. Is it because of my syntax or does JQL not support this kind of query? I read the documentation and as of now I haven't found anything regarding using variables.

 

Thanks!

1 answer

1 accepted

2 votes
Answer accepted
Alexey Matveev
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 Champions.
May 3, 2018

Hello,

JQL does not support using variables. You need to replace this variable with a value in your python script.

James Lester Desipeda
May 3, 2018

Thank you for answering! Does this mean I cannot do the action I intend to do or do you think there may be another way to implement this? I need this script to automate a task and using a variable in the query was the solution I had in mind, not until now.

James Lester Desipeda
May 3, 2018

Something came to my mind. Maybe I can automate editing the script to always change the JQL statement. Hmmmm

Alexey Matveev
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 Champions.
May 3, 2018

Yes, you can replace the variable in your python script and send a correct JQL statement.

Suggest an answer

Log in or Sign up to answer