Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

[Solved] POST JQL search to rest API

tjarles July 4, 2016

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?

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Petar Petrov (Appfire)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2016

The problem is that your data is from-encoded and not sent as JSON. You need to add:

headers: {'Content-Type': 'application/json'}
tjarles July 4, 2016

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")
});
Petar Petrov (Appfire)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2016

Can you post the full headers and body of the request, as retrieved from your browser's developer tools.

tjarles July 4, 2016

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}}

Petar Petrov (Appfire)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2016

Which browser are you using? There should be something which shows all the headers in the request.

tjarles July 4, 2016

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.

tjarles July 4, 2016

Chrome. I just took the fields I thought was relevant.

Petar Petrov (Appfire)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 4, 2016

So does it work now?

tjarles July 4, 2016

Yes! smile

Petar Petrov (Appfire)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 5, 2016

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.

TAGS
AUG Leaders

Atlassian Community Events