Issues search error: Unexpected character (''' (code <N>)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') - jira

I am trying to get this same type of query.
curl -u admin:admin -X POST localhost:50813/rest/api/2/search -H "Content-Type: application/json" -d '{"jql":"updated > -1d","fields":[""]}' -s | jq > jql-output.txt
But hitting error.
I ref this query from
https://confluence.atlassian.com/jirakb/how-to-programmatically-update-issues-from-a-jql-using-rest-api-in-jira-1031284474.html
Error which I am getting for now is to debug further.
curl -u admin:admin -X POST localhost:50813/rest/api/2/search -H "Content-Type: application/json" -d '{"jql":"updated > -1d","fields":[""]}'
Error:
{"errorMessages":["Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream#c502a0b; line: 1, column: 2]"]}
Any idea? Been trying various options. No clear solution

Yes, it seems this is a documentation error. You can basically remove the fields from request (and it returns all fields as default) or you can set it from one of the following as stated in another Jira documentation:
By default, only navigable (*navigable) fields are returned in this
search resource. Note: the default is different in the get-issue
resource -- the default there all fields (*all).
*all - include all fields
*navigable - include just navigable fields
summary,comment - include just the summary and comments
-description - include navigable fields except the description (the default is *navigable for search)
*all,-comment - include everything except comments
So basically, the request is should be like that:
curl -u admin:admin -X POST localhost:50813/rest/api/2/search -H "Content-Type: application/json" -d '{"jql":"updated > -1d"}'

Related

watson machine learning api - token refresh 400 error

I've successfully generated a token with the GET /v3/identity/token API. I now want to be able to leverage the PUT API to keep the token active.
I am trying this curl command:
curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' -d '<token-value>' 'https://ibm-watson-ml.mybluemix.net/v3/identity/token' -v -i --basic --user <username>:<password>
I get a 400 error stating:
For request 'PUT /v3/identity/token' [Invalid Json: Unexpected character ('-' (code 45)) in numeric value: expected digit (0-9) to follow minus sign, for valid numeric value at [Source: akka.util.ByteIterator$ByteArrayIterator$$anon$1#18bd12ef; line: 1, column: 3]]
The token returned from the get request has the dash character in it, along with other non-alphnumeric values.
Does the token from the get request need to be parsed? what am I missing?
You need to set your content-type to application/json. But -d sends the Content-Type application/x-www-form-urlencoded, which maybe is not accepted on IBM side.
But, seems like your JSON (token) are in the incorrect format.
The token value needs to be the following format (JSON):
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ"
}
And you need to follow the example of sent correctly the format:
curl -H 'Content-Type: application/json' -X PUT \
-d '{"token":"yourToken"}' \
https://ibm-watson-ml.mybluemix.net/v3/identity/token
See the official reference.

JIRA REST API JQL query issue with maxResults

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.

API documentation RAILS

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

Using curl for lira API with a period in the fixVersion jql

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;

curl POST request empty in ZF2 Rest API

I am testing my ZF2 Rest Module that is running on localhost, by sending curl POST requests from the same box.
curl -i -X POST -H "Content-Type: Application/json" -d '{username":"xyz","password":"xyz"}' http://localhost/api/login
In the corresponding controller and action, I have tried returning the POST parameters, but an empty array is returned always
var_dump($this->getRequest()); // returns: array(0){}
var_dump($_POST); // returns: array(0){}
If I switch from POST to GET with
curl -i -G -H "Content-Type: Application/json" -d '{username":"xyz","password":"xyz"}' http://localhost/api/login
it actually seems to work
var_dump($_GET); // returns: array(1) {["{"username":"xyz","password":"xyz"}"]=>string(0) ""}
Why is the POST request failing to pass/extract the parameters?
PHP only populates $_POST for form urlencoded POST data. You've explicitly set the content type to JSON, so the PHP way to access this would be:
file_get_contents("php://input");
In ZF2, I believe you want:
$this->getRequest()->getContent();
and in practice, you'll probably want to run this through json_decode().

Resources