0

Double mapflat? passing two variables to an API

Hi guys,

I have a table in a klip where I have 2 columns: "offerid" and "goalid", which is properly configured and populated.
I also have a dropdown tied to a varaible "affid" which is also working fine.

I have a 3rd column in my table called "payouts", to populate it, I must call upon an API with all 3 of the above parameters, in order to receive the payout.

API (example, not working link) -
https://myapi.com/Apiv3/json?NetworkToken=mytoken&Target=Offer&Method=getPayoutAndRevenueFactorsForAffiliate&id={props.offerid}&affiliate_id={props.affid}&goal_id={props.goalid}

For the API to work, I realize that I must have all 3 parameters saved as variables.
It's easy and done with the drop down (affid).
But the other 2 columns are a bit more tricky.

Had I only had 1 column, I would have use a simple MAPFLAT to iterate over the offerid OR the goalid, saving to a varaible, calling the API each time...done!
However, since I have 2 parameters, and both are needed for each request, it is like a two-dimensional MAPFLAT (one inside the other).

I tried that, but the end result was that I got WAY too many rows as a results as the two mapflats multiplied each other.
Maybe there is another approach? I saw in the community an approach to use REPEAT within a MAPFLAT with a SET inside... didn't manage to get it to work.

At the end of the day, I just need your help to store for each row the 2 variables, so that I could pull the correct data from our API.

Thanks,
Eduard

2 comments

  • 0
    Avatar
    Meggan King

    Hi Eduard,

    Thanks for posting here. I know we have been working on your issue via support, but would like to share a few tricks here. 

     

    For setting multiple variables, the function SET is the way to go: https://support.klipfolio.com/hc/en-us/articles/360011416893-Klipfolio-functions#SET

     

    SET can take an array of values and assign it to an array of variables to use in a function - such as complex logic, or to pass in for a dynamic data source. It's not a well known function, but can be very handy! This also gets away from needing multiple or nested MAPFLATS. 

     

    Hope this helps someone in the future!

    - Meggan

  • 0
    Avatar
    Eduard Kleiner

    Guys, I just want to say that Meggan is really a KING :-) 

    Thanks for your help, you're really great and got me out of a jam or two!!!

Please sign in to leave a comment.