Forums

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

Jira Server Search REST API returns all issues, ignoring jql, maxresults, fields args

shonji
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!
September 30, 2020

I'm trying to search for issues using trivial JQL, limiting the response to a small subset of fields using the POST variety of Jira Server's 'search' REST API. Lifting HTTP and data parameters from Atlassian's published search API examples , the response is ignoring the "jql", "maxresults", and "fields" data args and returns all issues in the db.

Python script:

# This code sample uses the 'requests' library:
# http://docs.python-requests.org
import requests
from requests.auth import HTTPBasicAuth
import json

url = "http://jira.companyX.com/rest/api/2/search"
auth = HTTPBasicAuth("user_name", "user_password")
headers = {
    "Accept": "application/json",
    "Content-Type": "application/json"
}

payload = json.dumps( {"jql":"project=DC","startAt":0,"maxResults":2,"fields":["id","key"]} )

response = requests.request(
    "POST",
    url,
    data=payload,
    headers=headers,
    auth=auth
)

print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))

Rather than scope the results to the JQL filter and maxResults, the response contains issues from all projects and all values for all fields in the db including custom fields, and terminates with:

"maxResults": 50,
"startAt": 0,
"total": 123215

The same command using CURL:

curl |
-D- |
-L |
-X POST |
-H "Authorization: Basic user_creds_in_base64" |
-H "Accept: application/json" |
-H "Content-Type: application/json" |
--data '{"jql":"project=DC","startAt":0,"maxResults":2,"fields":["id","key"]}' |
http://jira.companyX.com/rest/api/2/search

returns

{"errorMessages":["No content to map to Object due to end of input"]}

Anyone have an idea what might be amiss? Thanks!

 

2 answers

0 votes
shonji
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!
October 8, 2020

Hi Michael,

Thanks for having a look at this. The GET form is the first path I traveled and works fine. However, unlike the code I posted here -- which was much reduced to what amounts to the Atlassian code sample for the POST call -- the JQL for our production use case is anything but trivial. But your suggestion aligns with what is clear from my end: the --data arg is being completely ignored by the POST API.

I'm very much hoping someone from Atlassian can jump in and debug their own POST query example. If that's a-ok, then it should be obvious what is amiss with mine.

Cheers!

Michael Raj October 8, 2020

Hi @shonji ,

I believe "data" works if you want to send a data to Jira (using POST method).

If you want to collect data from Jira you use GET and details of the request put in url part.

 

Best

Michael

Scott Honji
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!
October 9, 2020

Hello Raj,

You are generally correct about GET vs POST. However, Jira’s issue query API offers both forms (see the “Search for Issues using POST” doclink in my starting post):

  1. a GET method that allows filter parameters embedded in the URL, each treated as an AND clause. 
  2. a POST method that supports unrestricted JQL as the “data member of the inbound json payload. 

I need the JQL support and therefore MUST use the POST form.

0 votes
Michael Raj October 6, 2020

Hi @shonji ,

in the guide mentioned by you, there is a section dedicated to searching. I would use those codes. https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#searching-for-issues-examples

That means instead of POST use GET.

And don't put attributes in "data" but in the url.

Example:

curl \
   -D- \
   -u charlie:charlie \
   -X GET \
   -H "Content-Type: application/json" \
   http://localhost:8080/rest/api/2/search?jql=assignee=charlie

 

Best

Michael

Suggest an answer

Log in or Sign up to answer