# Internal Error when applying two filters to Tulip API Table Query

**URL:** <https://community.tulip.co/t/internal-error-when-applying-two-filters-to-tulip-api-table-query/5401>\
**Category:** Support, Troubleshooting, & Help\
**Created:** [May 31, 2022, 8:43am UTC](https://community.tulip.co/t/internal-error-when-applying-two-filters-to-tulip-api-table-query/5401 "2022-05-31T08:43:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomReynolds98](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@TomReynolds98](https://community.tulip.co/u/TomReynolds98)\
**Post date:** [May 31, 2022, 8:43am UTC](https://community.tulip.co/t/internal-error-when-applying-two-filters-to-tulip-api-table-query/5401/1 "2022-05-31T08:43:37Z")

</div>

Hi, I am attempting to extract table records from tulip into node-red using the TulipAPI. When applying two filters to this I get an internal server error, status code 500. I believe the request to be properly formed and using only one filter does not throw up the same issue. Is anyone able to advise? I have pasted the request url below and the response.

https://-----/api/v3/tables/skLZrjDB5NijBdoGK/records/?limit=100&filters=[{“field”:“megyt\_location”,“arg”:“Line”,“functionType”:“equal”},{“field”:“jpmfg\_part\_id\_unlinked”,“arg”:“P\_4776”,“functionType”:“equal”}]&filterAggregator=all

{“errorCode”:“InternalServerError”,“details”:“Internal Server Error”,“errorUniqueID”:“oVgs5rZC744mq9jsLiocJaACszNnOMqmHSWVu5RAipw”}

---

<div class="post-metadata">

**Author:** ![Pete\_Hartnett](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/pete_hartnett/32/3678_2.png) [@Pete\_Hartnett](https://community.tulip.co/u/Pete_Hartnett)\
**Post date:** [May 31, 2022, 12:34pm UTC](https://community.tulip.co/t/internal-error-when-applying-two-filters-to-tulip-api-table-query/5401/2 "2022-05-31T12:34:29Z")

</div>

Hey @TomReynolds98,

I found our documentation to be lacking on this - Thanks for brining this up, I have made an action to resolve this. The way you need to add filters is below:

```auto
payload = {"limit": limit, 
    "offset": offset, 
    "includeTotalCount": "true", 
    "sortBy": "_updatedAt",
    "filters.0.field":"kzmxn_expected_time",
    "filters.0.functionType":"greaterThanOrEqual",
    "filters.0.arg":15}

```

Notice how I don’t pass a whole json encoded object to the filter attribute, I pass each individual filter as standard attributes.

I found this confusing (or just completely lacking of documentation) the first time I did this too. A second filter could be added with the code:

```auto
"filters.1.field":"kzmxn_line_number",
    "filters.1.functionType":"greaterThanOrEqual",
    "filters.1.arg":3

```

Does this resolve what you’re seeing?  
Pete

---

<div class="post-metadata">

**Author:** ![TomReynolds98](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@TomReynolds98](https://community.tulip.co/u/TomReynolds98)\
**Post date:** [May 31, 2022, 2:30pm UTC](https://community.tulip.co/t/internal-error-when-applying-two-filters-to-tulip-api-table-query/5401/3 "2022-05-31T14:30:21Z")

</div>

Hi Pete,  
I have placed a function node in front of the tulip api call that uses the format above,

payload =  
{  
“limit”: 100,  
“offset”: 0,  
“includeTotalCount”: “true”,  
“sortBy”: “\_updatedAt”,  
“filters.0.field”:“megyt\_location”,  
“filters.0.functionType”:“equal”,  
“filters.0.arg”:“Line”,  
“filters.1.field”:“jpmfg\_part\_id\_unlinked”,  
“filters.1.functionType”:“equal”,  
“filters.1.arg”:“P\_4776”  
}  
return msg;

If I use payload at the start it returns the whole table, i.e. the filters aren’t present  
If I use msg.filters at the start (seemed logical potential option), I get error code 400 and Invalid Query String, “Unable to parse query string: error parsing query value for `filters` as JSON: invalid character ‘o’ looking for beginning of value”.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/7/77cfc4490e44bcc4c45428a5f448b589f3f23cec.png)

Hope that makes sense, if you have a 2 filter set of nodes working could I potentially get the exported JSON of the flow to edit and try on mine?

Thanks,  
Thomas

---

<div class="post-metadata">

**Author:** ![Pete\_Hartnett](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/pete_hartnett/32/3678_2.png) [@Pete\_Hartnett](https://community.tulip.co/u/Pete_Hartnett)\
**Post date:** [May 31, 2022, 3:16pm UTC](https://community.tulip.co/t/internal-error-when-applying-two-filters-to-tulip-api-table-query/5401/4 "2022-05-31T15:16:31Z")

</div>

Hey @TomReynolds98,

Sorry, my code snippet was pulled out of python instead of NR. Should only need one small change.

The tulip-tables node takes the payload on the msg.body attribute. so if you change your function to this you should be good to go:

```auto
msg.body =
{
“limit”: 100,
“offset”: 0,
“includeTotalCount”: “true”,
“sortBy”: “_updatedAt”,
“filters.0.field”:“megyt_location”,
“filters.0.functionType”:“equal”,
“filters.0.arg”:“Line”,
“filters.1.field”:“jpmfg_part_id_unlinked”,
“filters.1.functionType”:“equal”,
“filters.1.arg”:“P_4776”
}
return msg;

```

Wanna give this a go and let me know if you still have errors?  
Pete

---

<div class="post-metadata">

**Author:** ![Pete\_Hartnett](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/pete_hartnett/32/3678_2.png) [@Pete\_Hartnett](https://community.tulip.co/u/Pete_Hartnett)\
**Post date:** [May 31, 2022, 3:52pm UTC](https://community.tulip.co/t/internal-error-when-applying-two-filters-to-tulip-api-table-query/5401/5 "2022-05-31T15:52:43Z")

</div>

Hey @TomReynolds98 -

Talked more with our hardware team (the NR masters internally). Attached is a flow you can import that is the way they would approach filtering. Turns out the tulip-tables node does some of the filter encoding automatically, so it can be done on the msg.filter attribute. So for example-

```auto
msg = { 
    "tableId": "theirTableID",
    "limit": 100,
    "offset": 0,
    "includeTotalCount": true,
    "sortBy": "_updatedAt"
};
msg.filters = [{
    "field": "megyt_location",
    "functionType": "equal",
    "arg": "Line"
}, {
    "field": "jpmfg_part_id_unlinked",
    "functionType": "equal",
    "arg": "P_4776"
}];

```

Apologies! Didn’t realize the nodes were _smarter_ than the normal api calls.

Attached is a flow we just tested in the QA lab  
[Filter.json](https://community.tulip.co/uploads/short-url/pvqIaTvoVONRurGfCmxgKYvUCBR.json) (2.8 KB)

---

<div class="post-metadata">

**Author:** ![TomReynolds98](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@TomReynolds98](https://community.tulip.co/u/TomReynolds98)\
**Post date:** [May 31, 2022, 4:06pm UTC](https://community.tulip.co/t/internal-error-when-applying-two-filters-to-tulip-api-table-query/5401/6 "2022-05-31T16:06:21Z")

</div>

Hi Pete,

Was just working through the first one and that unfortunately this still gives the whole table being returned.

And then, doing the second one., I’ve imported your nodes and edited for my table and this also throws up internal server error, code 500.

However when I apply this method to another table the double filter does work as intended!

I wonder if there is something the matter with the table itself that’s throwing up the issue?

I’m happy to mark the above as the solution as it does work, just not for this specific table it seems.

Thanks,  
Thomas

---

<div class="post-metadata">

**Author:** ![TomReynolds98](https://avatars.discourse-cdn.com/v4/letter/t/d78d45/32.png) [@TomReynolds98](https://community.tulip.co/u/TomReynolds98)\
**Post date:** [May 31, 2022, 4:17pm UTC](https://community.tulip.co/t/internal-error-when-applying-two-filters-to-tulip-api-table-query/5401/7 "2022-05-31T16:17:35Z")

</div>

In fact, It is now working on this table also so all good!

Thanks for all your efforts!  
Thomas

---

<div class="post-metadata">

**Author:** ![NitinKolhe](https://avatars.discourse-cdn.com/v4/letter/n/41988e/32.png) [@NitinKolhe](https://community.tulip.co/u/NitinKolhe)\
**Post date:** [January 18, 2024, 3:25am UTC](https://community.tulip.co/t/internal-error-when-applying-two-filters-to-tulip-api-table-query/5401/8 "2024-01-18T03:25:17Z")

</div>

Hi Pete,  
How dynamic filters should apply for tables, like  
msg.filters = [{  
“field”: “megyt\_location”,  
“functionType”: “equal”,  
“arg”: “Line”---------- //In arg i want to compare this with another table column.  
},];

---

<div class="post-metadata">

**Author:** ![Pete\_Hartnett](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/pete_hartnett/32/3678_2.png) [@Pete\_Hartnett](https://community.tulip.co/u/Pete_Hartnett)\
**Post date:** [January 18, 2024, 9:47pm UTC](https://community.tulip.co/t/internal-error-when-applying-two-filters-to-tulip-api-table-query/5401/9 "2024-01-18T21:47:57Z")

</div>

Hey @NitinKolhe -

Check out [this](https://community.tulip.co/t/internal-error-when-applying-two-filters-to-tulip-api-table-query/5401/4) thread, where I give some examples of how to do filtering on the tables api from node red.

Pete
