JIRA's REST API search doesn't honor maxResults parameter.
curl -o lambrusco.txt -k -D- -u admin:admin -X GET -H "Content-Type: application/json" https://jira.domain.com/rest/api/2/search?jql=assignee=blackpearl&startAt=0&maxResults=4
No matter what maxResults is, it always returns 50 results.
Output:
{"expand":"schema,names","startAt":0,"maxResults":50,"total":61,"issues":[{"expand":"operations,versionedRepresentations,editmeta,changelog,transitions,renderedFields","id":"15588","self": ...}
What am I missing here?
Your request looks fine. Here is example on official Atlassian JIRA, which works fine:
curl -X GET -H "Content-Type: application/json" "https://jira.atlassian.com/rest/api/2/search?jql=assignee=tlay&startAt=1&maxResults=1" | jq -r '.maxResults'
It looks like that it's related to REST API Bug!
You need to quote the request when using curl as shown by #grundic, otherwise the shell will interpred the ampersand. And note that the API is case sensitive.
Related
Swagger UI generating wrong Curl command as pasted below and due to this query string truncating
curl -X GET http://domain:8080/v1/endpoint?access_token=affsfafasfa&type=1 -H "accept: application/json" -H "content-type: application/json"
the correct Curl command should be like this
curl -X GET 'http://domain:8080/v1/endpoint?access_token=affsfafasfa&type=1' -H "accept: application/json" -H "content-type: application/json"
the difference between above two command is quote around http url . So please tell me how to achieve this in swagger ui ?
I guess you found a bug in the new version. The very latest code already contains a fix for it.
Its an bug in swagger ui version 3.0.2 and swagger support team has fixed this bug now https://github.com/swagger-api/swagger-ui/issues/2839
I currently trying to get the issues from JIRA via REST API via this:
curl -D- -u USERNAME -X GET -H "Content-Type: application/json" \
https://issues.apache.org/jira/rest/api/2/search? jql=project%20%3D%20MNG%20AND%20fixVersion%20%3D%203.4.0 \
-o release.json
But unfortunately i don't get all issues. Only 50 instead of 59. I already checked if all the issues have the correct fixVersion set to 3.4.0.
But via browser:
https://issues.apache.org/jira/issues/?jql=project%20%3D%20MNG%20AND%20fixVersion%20%3D%203.4.0
I got all the issues.
Do i oversight something ? Some idea hint ?
50 is a default value for "maxResults" parameter. Here's API documentation https://docs.atlassian.com/jira/REST/latest/#api/2/search-search
For my first API documentation (very simple API, only one method) I have more or less this structure:
API documentation
1.Disclaimer
2. Using the API
2.1 Input data -> Here I explain how should be the input data, JSON
2.2 Output data > Here I explain which data should be obtained and in JSON
2.3 Example -> I am giving an example of my input and output
In 2.3 I explain that the output (real example in my documentation, I post here only a structure of how it looks) should look like this:
{"message":"Succesful ","data":{"batt1":{"value1":977.48279000017,"value2":977.4208279000022,"value3":1034.9372639500002,"value4":2534.854048049996,"value5":2465.145176450681,"value6":2465.1451764508347},"batt2":{}...}
But its missing me how to put the request in this example.
Until now I have been using/ testing my API with this command: curl -i -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '#alldata.json' http://localhost:3000/api/v1/namecontroller
Should I put in my documentaion in 2.3 something like this:
In this example I used the cURL command in the following form: curl -i -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '#alldata.json' http://localhost:3000/api/v1/namecontroller
Sorry I am very new to all this, RoR,API etc...
Do you have any idea?
I think you can show it in below format so that will be easy to understand
url: http://localhost:3000/api/v1/namecontroller
method: POST
Body : #alldata.json
I've tried various iterations of using either ", ' and ` to enclose a curl query to an instance of jira in order to get all issues for a particular fix Version.
curl -D- -u username:password -X POST -H "Content-Type: application/json" -d '{"jql":"project = PROJ AND fixVersion=Version-1.2.3"}' "https://thejirainstall.com/jira/rest/api/2/search"
However, using this and a couple of other change on fixVersion such as:
fixVersion="Version-1.2.3"
or
fixVersion=\"Version-1.2.3\"
or
fixVersion=Version-1\u002e2\u002e3
Add and remove quotes at will.
The ones that don't fail outright return:
{"errorMessages":["Error in the JQL Query: '\\.' is an illegal JQL escape sequence. The valid escape sequences are \\', \\\", \\t, \\n, \\r, \\\\, '\\ ' and \\uXXXX. (line 1, character 38)"],"errors":{}}
How do I either escape periods . or add another set of quotes?
Ok, so it turns out that Jira doesn't permit version names in jql syntax. The version id must be used instead.
And, in order to get the version id you must parse the result from https://thejirainstall.com/jira/rest/api/2/project/ON/versions?
This now means that I have to use a JSON parser anyway. So, now I'm using jq via homebrew install jq
My current solution is to write a bash script as below:
JIRA_FIXVERSION
fixVersionQuery='https://thejirainstall.com/jira/rest/api/2/project/ON/versions?';
myJSONResponse=`curl -u username:password -X GET -H "Content-Type: application/json" --insecure --silent $fixVersionQuery |jq '.[] | {id,name} | select(.name=="Version-1.2.3" | .["id"]'`;
echo $myJSONResponse;
I am using cURL command line utility to send HTTP POST to a web service. I want to include a file's contents as the body entity of the POST. I have tried using -d </path/to/filename> as well as other variants with type info like --data </path/to/filename> --data-urlencode </path/to/filename> etc... the file is always attached. I need it as the body entity.
I believe you're looking for the #filename syntax, e.g.:
strip new lines
curl --data "#/path/to/filename" http://...
keep new lines
curl --data-binary "#/path/to/filename" http://...
curl will strip all newlines from the file. If you want to send the file with newlines intact, use --data-binary in place of --data
I know the question has been answered, but in my case I was trying to send the content of a text file to the Slack Webhook api and for some reason the above answer did not work. Anywho, this is what finally did the trick for me:
curl -X POST -H --silent --data-urlencode "payload={\"text\": \"$(cat file.txt | sed "s/\"/'/g")\"}" https://hooks.slack.com/services/XXX
In my case, # caused some sort of encoding problem, I still prefer my old way:
curl -d "$(cat /path/to/file)" https://example.com
curl https://upload.box.com/api/2.0/files/3300/content -H "Authorization: Bearer $access_token" -F file=#"C:\Crystal Reports\Crystal Reports\mysales.pdf"