Can't get JA API 2.0 to have multiple filters
Asked by Mark Dodrill:

I am trying to make use of the Jira Align API 2.0 to get some specific Feature data. I've been using this wiki page to help guide me on the structure of the URLs to get the data:

<https://help.jiraalign.com/hc/en-us/articles/360060894632-Supported-API-2-0-Query-Syntax>

Unfortunately, there aren't any examples of using multiple filters at the same time, to select both a Program ID and another field.

Here is my CURL command:

curl -X GET "[https://blah.jiraalign.com/rest/align/api/2/Features?$filter=((primaryProgramId%20eq%2058)%20and%20(externalProject%20eq%20'CORE'))\&$select=id,title,releaseId,externalKey,externalProject,primaryProgramId,releaseVehicleIds](https://blah.jiraalign.com/rest/align/api/2/Features?$filter=((primaryProgramId%20eq%2058)%20and%20(externalProject%20eq%20'CORE'))&$select=id,title,releaseId,externalKey,externalProject,primaryProgramId,releaseVehicleIds)" -H 'Authorization: Bearer user:117' -H 'Accept: application/json'\| jq .

I have also tried:

curl -X GET "[https://blah.jiraalign.com/rest/align/api/2/Features?$filter=(primaryProgramId%20eq%2058)%20and%20(externalProject%20eq%20'CORE')\&$select=id,title,releaseId,externalKey,externalProject,primaryProgramId,releaseVehicleIds](https://blah.jiraalign.com/rest/align/api/2/Features?$filter=(primaryProgramId%20eq%2058)%20and%20(externalProject%20eq%20'CORE')&$select=id,title,releaseId,externalKey,externalProject,primaryProgramId,releaseVehicleIds)" -H 'Authorization: Bearer user:117' -H 'Accept: application/json'\| jq .

and

curl -X GET "[https://blah.jiraalign.com/rest/align/api/2/Features?$filter=primaryProgramId%20eq%2058%20and%20externalProject%20eq%20'CORE'\&$select=id,title,releaseId,externalKey,externalProject,primaryProgramId,releaseVehicleIds](https://blah.jiraalign.com/rest/align/api/2/Features?$filter=primaryProgramId%20eq%2058%20and%20externalProject%20eq%20'CORE'&$select=id,title,releaseId,externalKey,externalProject,primaryProgramId,releaseVehicleIds)" -H 'Authorization: Bearer user:117' -H 'Accept: application/json'\| jq .

By looking at the output, I can confirm that neither part of my Filter is being used.

Any ideas how I can make this work? If I use just one of these at a time, it works as expected, but I need both.

Thanks.


Answers:
author: Mark Dodrill
body: Ok, I now have a command that works for how I want:

curl -X GET '[https://foo.jiraalign.com/rest/align/api/2/Features?$filter=primaryProgramId%20eq%2058%20and%20jiraProjectKey%20eq%20%27CORE%27\&$select=id,title,releaseId,externalKey,jiraProjectKey,primaryProgramId,releaseVehicleIds](https://foo.jiraalign.com/rest/align/api/2/Features?$filter=primaryProgramId%20eq%2058%20and%20jiraProjectKey%20eq%20%27CORE%27&$select=id,title,releaseId,externalKey,jiraProjectKey,primaryProgramId,releaseVehicleIds) ' -H 'Authorization: Bearer user:117' -H 'Accept: application/json'\| jq .

... {  
"id": 16178,  
"title": "\[ENABLER\] feature1",  
"releaseId": null,  
"externalKey": "CORE-338",  
"jiraProjectKey": "CORE",  
"primaryProgramId": 58,  
"releaseVehicleIds": \[\]  
},  
{  
"id": 16180,  
"title": "feature2",  
"releaseId": 62,  
"externalKey": "CORE-302",  
"jiraProjectKey": "CORE",  
"primaryProgramId": 58,  
"releaseVehicleIds": \[  
1344  
\]  
}  
\]

Key seems to be the %27 around the string to compare against.

comments: author: Kirill Duplyakin
body: Awesome!

Yeah seems like there are a few potential issues to do with special characters/ accepted format. Glad you were able to find what works!


author: Kirill Duplyakin
body: Hi [@Mark Dodrill](/t5/user/viewprofilepage/user-id/2731523),

This seems to work for me. Both filters are applied and if they don't overlap, I get an empty list.

1. You mentioned that you get some results, do they literally have the wrong *primaryProgramId* and *externalProject*?
2. Could you anonymize the results and show them here?
3. I tried this in Insomnia really quickly, I'm wondering if you could try Postman or Insomnia too, does it give the same results?
4. Do you have other filter queries that worked ok?
5. Another thing I noticed is that *externalProject* field references ADO connector project and it's *null* if you have Jira connector project (can use *jiraProjectKey* for Jira).   
   As having ADO connector is less common - do you mean to use it?

For reference here's what I tried:

```
https://testsite.jiraalign.com/rest/align/api/2/features?$filter=primaryProgramId eq 999 and externalProject eq '9'&$select=id,title,releaseId,externalKey,externalProject,primaryProgramId,releaseVehicleIds
```

Hope we can find out more, curious why it works for me but not in your environment ?

comments: author: Kirill Duplyakin
body: Hi [@Mark Dodrill](/t5/user/viewprofilepage/user-id/2731523)

I went ahead and tried Curl as well and ran into the same issue.

What solved it was every single $ sign needs to be escaped using \\ in cli. Here's the command that worked in the end:

```
curl -X GET -H "Authorization: Bearer token" "https://testsite.jiraalign.com/rest/align/api/2/features?\$filter=(primaryProgramId%20eq%20999%20and%20externalProject%20eq%20'9')&\$select=id,title,releaseId,externalKey,externalProject,primaryProgramId,releaseVehicleIds"?
```

Hope this helps!


author: Mark Dodrill
body: Hmm, strange. I added the escapes of $, but made no difference:

curl -X GET '[https://foo.jiraalign.com/rest/align/api/2/Features?\\](https://foo.jiraalign.com/rest/align/api/2/Features?\)$filter=primaryProgramId%20eq%2058%20and%20externalProject%20eq%20CORE\\\&\\$select=id,title,releaseId,externalKey,primaryProgramId,releaseVehicleIds ' -H 'Authorization: Bearer user:117' -H 'Accept: application/json'\| jq . \| grep primary

Output is:

"primaryProgramId": 4,  
"primaryProgramId": 4,  
"primaryProgramId": 4,  
"primaryProgramId": 4,  
"primaryProgramId": 4,  
"primaryProgramId": 4,

Which is wrong. It should be 58, not 4.

"externalProject": null,

Should be CORE.

Yes, I can confirm that the data returned does not include the right data for the fields in the filter.

Not sure why I'm having this problem. I thought it would be easier to get this data in BASH rather than writing a program. :(


author: Mark Dodrill
body: Doing more trial and error, I think the issue is around how to represent non-numeric values in the comparison (i.e. string comparisons). This query works correctly and uses both filter values in what it returns and doesn't seem to require special quoting of \& or $:

curl -X GET '[https://foo.jiraalign.com/rest/align/api/2/Features?$filter=primaryProgramId%20eq%2058%20and%20releaseId%20eq%2062\&$select=id,title,releaseId,externalKey,primaryProgramId,releaseVehicleIds](https://foo.jiraalign.com/rest/align/api/2/Features?$filter=primaryProgramId%20eq%2058%20and%20releaseId%20eq%2062&$select=id,title,releaseId,externalKey,primaryProgramId,releaseVehicleIds) ' -H 'Authorization: Bearer user:117' -H 'Accept: application/json'\| jq .

...  
{  
"id": 17318,  
"title": "feature1",  
"releaseId": 62,  
"externalKey": "CORE-2264",  
"primaryProgramId": 58,  
"releaseVehicleIds": \[  
1344  
\]  
},  
{  
"id": 17327,  
"title": "\[Design Spike\] feature2",  
"releaseId": 62,  
"externalKey": "CORE-2185",  
"primaryProgramId": 58,  
"releaseVehicleIds": \[  
1344  
\]  
},  
...


Tags: cloud