Forums

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

What does a JQL query look like in JSON?

Randy Smith August 3, 2023

Just learning to use the Jira REST API and I have most things figured out, but even though there are a ton of resources about the JQL functions, operators, and more, there's no examples that I have found on how to write said query inside of the JSON you submit to run the query.

I'm using CFML, but even if you're not familiar with it, most programmers will recognize what I'm trying to do.  and, no, I am not sure I have the right URL or "expand" or "issues" stuff right.  This is my first attempt at this area.

 

<cfset bodyValue = '{
    "jql": {created > 2023/07/31 AND labels="BugTracker" AND summary ~ "Randy Is Testing"},
    "expand": "names,schema",
    "startAt": 0,
    "maxResults": 50,
    "total": 1,
    "issues": [
        {
            "expand": "",
            "key": "#tProjectKey#"
        }]
    }' />
    <cfhttpparam type="header" name="Authorization" value="Basic #t64encode#">
    <cfhttpparam type="header" name="Content-Type"  value="application/json">
    <cfhttpparam type="body" value="#bodyValue#">
</cfhttp>

2 answers

1 accepted

0 votes
Answer accepted
Charlie Misonne
Community Champion
August 3, 2023

Hi Randy,

I do not have any experience with CFML.

Here is the REST API documentation: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-search/#api-rest-api-3-search-post
You will see an example JSON on that page.

Try using v3 instead of v2 if you are on Jira Cloud: /rest/api/3/search.
Altough this will not change much for this specific API endpoint.

You don't need to wrap the JQL around curly braces. Just put double quotes around them. Because you already have double quotes in the JQL you will need to escape those with a backslash.
Try this:

"jql": "created > 2023/07/31 AND labels=\"BugTracker\" AND summary ~ \"Randy Is Testing\""

 

I'm not sure where the "issues" part comes from in your example?

Randy Smith August 3, 2023

The "issues" part comes from me misunderstanding what was needed. :-)

This also works (below) for both api 2 and 3. Thank you for the link to that reference!

 

<cfset bodyValue = '{
    "jql":"project=myprojecthere AND created > \"2023/07/31\" AND issuetype=bug AND labels=BugTracker AND summary ~ \"Is Testing\"",
    "expand": ["names"],
    "fields":["key","summary","details"],
    "startAt": 0,
    "maxResults": 10
    }' />
    <cfhttpparam type="header" name="Authorization" value="Basic #t64encode#">
    <cfhttpparam type="header" name="Content-Type"  value="application/json">
    <cfhttpparam type="body" value="#bodyValue#">
</cfhttp>
<cfset tJSON=DeserializeJSON(cfhttp.filecontent)>
Charlie Misonne
Community Champion
August 4, 2023

ok glad I could help!

0 votes
Randy Smith August 3, 2023

Thank you for your response!

I stumbled upon the answer just as yours was coming in - this worked for me:

<cfhttp url="https://cfcorg.atlassian.net/rest/api/2/search?jql=created > '2023/07/31' AND issuetype=bug AND labels=BugTracker AND summary ~ 'Randy Is Testing'" method="GET">
    <cfhttpparam type="header" name="Authorization" value="Basic #t64encode#">
    <cfhttpparam type="header" name="Content-Type"  value="application/json">
</cfhttp>
From there, I was able to re-introduce the bodyValue, although I'd love to be able to reduce my result to just the ticket keys that were found, but I can work around that.
Now I'm going to try to put the jql into the JSON using the example you provided.
Thanks again!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events