FIltering API response for List of items (lookup) > Remote List


(Jun Nakashima) #1

I want to create a “List of items(lookup)” Entity based on the values stored in another web service.
The web service has an API to GET these values, so I am using the Remote List function.
Unfortunately the API returns values that I don’t want to use as an item, and was wondering if there was a way to filter the API response before assigning it to the list.
This is an idea of what I want to do.

API Response

{response :
{categories :
{“id”: 1, “name”: “aaa”, “deleteFlag”: 0},
{“id”: 2, “name”: “bbb”, “deleteFlag”: 1},
{“id”: 3, “name”: “ccc”, “deleteFlag”: 0},
{“id”: 4, “name”: “ddd”, “deleteFlag”: 0}
}
}

Entity List (I want to filter out the item where the deleteFlag is 1)

ValueKey: 1, Display Name Key: aaa
ValueKey: 3, Display Name Key: ccc
ValueKey: 4, Display Name Key: ddd


(Swagat) #2

Sure you can do that using a script node post the service node (assuming you are using the service node for API call).
You will have to write a custom javascript to iterate through the response.
It will be beneficial if you can have the response in a JSON array.


(Jun Nakashima) #3

Thank you. This worked perfectly!


(Subrahmanyam Donepudi) #4

We also suggest to take advantage of koreUtil libraries which serve as programming tools to work on the object and arrays at the js editors provided through out the bot builder at various places. EX: koreUtil._

Please refer to below link for more details.

https://developer.kore.ai/docs/bots/advanced-topics/koreutil-libraries/