Filtering magic repeat data collection

(SANG) #1

I there

I am doing testing http get request and send as message
I am using collection data output with magic repeat {{api_string_request.data__header__result__0___name *}}
its work perfectly

my problem was , filtering data output with magic repeat on send message service , its not show anything ,
the log said no input or output
is its possible to filtering magic repeat collection data output , directly on send message or message card service

thanks before

(John Jackson) #2

It’s not possible to use the modifiers such as magic repeat with filters, unfortunately.

What you can do is create a ‘dummy’ step where you use something like the Text (String) ‘Join Text’ to join your magic repeat output only, which will make the magic repeat into a normal output of the ‘Join Text’ action.

Now, you can filter on the output from ‘Join Text’ successfully.

(SANG) #3

thank you for quick reply john

actually I just want to filter my http request result , before I send message to user
I found magic repeat is very easy doing recursive send message

is there is other way to filter my http request result before I send messsage to user ?

(John Jackson) #4

Do you need to filter on a property inside a JSON response? Can you give me an idea of what you get back and how you’d like to filter? I’ll certainly try and help :thumbsup:

(Szymon) #5

I’m gonna ask here, as this use case seems similar to mine.

I’m getting a Webhook with JSON response. As I don’t have control over what’s being sent, I’m getting more responses than I’d like to act on. Therefore I’d like to filter out all unneeded triggers by comparing 2 values in the received JSON. How could I achieve that (outside of using the Code service - this would kill my usage meters)?

(SANG) #6

HI john

after Get Http request , I get 20 result response in JSON format
Result { [
Product name
Product type
price
size
color
]}

now I like to send the message to user only the product with red color , from 20 result response of http request
there is only 5 in red color
and I like to send only this 5 result to user

I hope my explanation not confusing you :slight_smile:
my test before is using Magic repeat on bot send message , and when I apply filter on send bot message its not working , I think magic repeat can’t working with filter

please help how to do this

(John Jackson) #7

You’ll need to use the code service right after you fetch the data, to remove any items that have the red color.

You can something similar to this, swapping {{ MISSING OUTPUT }} for the output that holds the data.

This is the code:

var output = [];

inputs.data.forEach(function(item) {
  if (item.color === "red") {
    output.push(item);
  }
});

resolve(output);

It is going through each item, and if the color is red, adding it to a new array. That is then sent as the output of this action. So you can then use the magic repeat on the output you get from this and that will hopefully do what you need it to.

Good luck with it :slight_smile:

(SANG) #8

HI John

its work :wink:

however its will be great if magic repeat can be filter without code , also magic repeat can be apply on “send a card”

Many thanks
Sang