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!
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!
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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):
I need the JQL support and therefore MUST use the POST form.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.