Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira REST API Filter getting 400 status and connection close

Bhagavan Goud
Contributor
February 9, 2022

function CreateFilter(keyValue,projectKey,boxId)
{

AJS.$.ajax
({
url: baseUrl + '/rest/api/2/filter/',
type: "POST",
timeout: 0,
dataType: 'json',
processData: false,
headers: {
"Content-Type": "application/json; charset=utf-8",
"Access-Control-Allow-Origin": "*"
},

data: JSON.stringify({"name":keyValue+"-BigPicture","jql":"\"Project ebm-papst\" = "+keyValue,"favourite":true}),

success: function (response)
{
filter={name:response.name,url:response.viewUrl,value:response.id};
getUserKey(filter,boxId);
console.log(JSON.stringify(response));
alert("box added");
},

error: function (response)
{
console.log(JSON.stringify(response));

}


});
}

 

 

Screenshot (198).png

2 answers

1 accepted

0 votes
Answer accepted
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 15, 2022

Hi @Bhagavan Goud 

I see that you are looking to create a filter via rest for Jira, using what looks to be like a javascript style call.   The fact that you see a HTTP 400 error tends to indicate that the way the call is being made is incorrect, or there is a bad payload supplied here.

From the URL in your call, it looks like you're using either Jira Server or Jira Data Center.  Could you please let me know which version of Jira you are using here?  I ask because the REST API endpoints have recently changed for a number of server endpoints.  For example, in Jira 8.13.0 the endpoint is documented in https://docs.atlassian.com/software/jira/docs/api/REST/8.13.0/#api/2/filter-createFilter as being POST /rest/api/2/filter

But for 8.21.0 we can see the reference page over in https://docs.atlassian.com/software/jira/docs/api/REST/8.21.0/#filter-createFilter shows that endpoint is now POST /rest/filter

If you're on a more recent Jira version, it could be that the endpoint your script is calling is now out of date.

 

But if that is not the cause of this problem here, I noticed that the JSON payload looks a bit off to me.  The JQL value for example is shown as

"jql":"\"Project ebm-papst\" = "+keyValue

Perhaps my understanding of how javascript will parse this is incorrect, but I expect that if your JQL is something like

Project = ebm-papst

Then we would need to have that equals sign immediately following the project term.

But even so, if you get this kind of 400 error again, try clicking the Response tab shown in your screenshot.  Perhaps the response Jira provides might give us additional hints as to why this call is not working as expected here.

Andy

Bhagavan Goud
Contributor
February 16, 2022

HI @Andy Heinzer

I'm using the Jira version is 8.20.2 and how I would like to give JQL

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 16, 2022

Thanks for that info.  It is as I expected.  The endpoint name has changed in this updated version of Jira.  Try adjusting your script to call POST /rest/filter instead. You can change the line that contains:

url: baseUrl + '/rest/api/2/filter/',

Into

url: baseUrl + '/rest/filter/',

And that should then allow that version of Jira to understand the call you are trying to make here.

Try that and let me know if that helps.

Andy

Bhagavan Goud
Contributor
February 24, 2022

@Andy Heinzer,

Thank you for the information it's working.

Like Andy Heinzer likes this
0 votes
Bhagavan Goud
Contributor
February 16, 2022

Trying to findout

Suggest an answer

Log in or Sign up to answer