I'm trying to search through the JIRA REST API through angularjs. GET works fine:
$http({ method: "GET", url: 'http://test-url/rest/api/2/search?jql=' + 'reporter=reporter01' + '&project=project02' }).then(function successCallback(response) { return response.data; }, function errorCallback() { console.log("Error calling API") });
But POST does not:
$http({ method: "POST", url: 'http://test-url/rest/api/2/search', data: JSON.stringify({ jql: { reporter: "reporter01", project: "project02", maxResults: 20, } }) }).then(function successCallback(response) { return response.data; }, function errorCallback() { console.log("Error calling API") });
Which returns Error 400 with the message:
"Can not deserialize instance of java.lang.String out of START_OBJECT token at [Source: org.apache.catalina.connector.CoyoteInputStream@245c4092; line: 1, column: 2] (through reference chain: com.atlassian.jira.rest.v2.search.SearchRequestBean["jql"])"
Can anyone see what the problem is?
Community moderators have prevented the ability to post new answers.
The problem is that your data is from-encoded and not sent as JSON. You need to add:
headers: {'Content-Type': 'application/json'}
Thanks for the reply! Unfortunately I still have the same error message with this code:
$http({ method: "POST", url: 'http://test-url/rest/api/2/search', headers: {'Content-Type': 'application/json'}, data: JSON.stringify({ jql: { reporter: "reporter01", project: "project02", maxResults: 20, } }) }).then(function successCallback(response) { return response.data; }, function errorCallback() { console.log("Error calling API") });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you post the full headers and body of the request, as retrieved from your browser's developer tools.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I assume you mean these two (they are from the browser):
Header: http://odart-test.arrisi.com:8080/rest/api/2/search
Body: {jql: {reporter: "app-kbs-jira01", project: "KREATV", maxResults: 20}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Which browser are you using? There should be something which shows all the headers in the request.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Haha. Project should just be a single string and is the value of jql and reporter is apparently not a field:
{jql: "project = KREATV", maxResults: 20}}
That took the entire forenoon.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So does it work now?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cool! Actually I overlooked the second part of the error message, which pointed to the cause: com.atlassian.jira.rest.v2.search.SearchRequestBean[
"jql"
]) - a string is expected, while an object is received.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.