Parsing and Array and adding new row to database

Hi to everyone,
I have just started using activepieces!

I have a flow where I connect to an adserver to retrieve the websites.
The issue is that I get as a response by the adserver an array of websites, the goal is creating a new row to the database for each site.
Please can you help?

the output is the following array:
{
“body”: {
“data”: [
{
“date”: “2024-04-23T00:00:00+00:00”,
“revenue”: 0.01,
“bid_wons”: 14,
“sitename”: “web65”,
“impressions”: 12,
“bid_requests”: 931,
“bid_responses”: 112,
“endpoint_requests”: 7,
“delivered_pod_duration”: 51.43,
“requested_pod_duration”: 60
},
{
“date”: “2024-04-23T00:00:00+00:00”,
“revenue”: 1.04,
“bid_wons”: 1391,
“sitename”: “web8”,
“impressions”: 1395,
“bid_requests”: 117322,
“bid_responses”: 8072,
“endpoint_requests”: 1154,
“delivered_pod_duration”: 37.36,
“requested_pod_duration”: 60
},
{
“date”: “2024-04-23T00:00:00+00:00”,
“revenue”: 0.26,
“bid_wons”: 517,
“sitename”: “web5”,
“impressions”: 514,
“bid_requests”: 54580,
“bid_responses”: 2876,
“endpoint_requests”: 389,
“delivered_pod_duration”: 41.66,
“requested_pod_duration”: 60
},
{
“date”: “2024-04-23T00:00:00+00:00”,
“revenue”: 5.01,
“bid_wons”: 1415,
“sitename”: “web4”,
“impressions”: 1422,
“bid_requests”: 86095,
“bid_responses”: 13045,
“endpoint_requests”: 863,
“delivered_pod_duration”: 49.92,
“requested_pod_duration”: 60
},
{
“date”: “2024-04-23T00:00:00+00:00”,
“revenue”: 0.15,
“bid_wons”: 269,
“sitename”: “web3”,
“impressions”: 167,
“bid_requests”: 21824,
“bid_responses”: 1704,
“endpoint_requests”: 219,
“delivered_pod_duration”: 25.19,
“requested_pod_duration”: 60
},
{
“date”: “2024-04-23T00:00:00+00:00”,
“revenue”: 0,
“bid_wons”: 654,
“sitename”: “Web”,
“impressions”: 0,
“bid_requests”: 27673,
“bid_responses”: 8546,
“endpoint_requests”: 324,
“delivered_pod_duration”: 0,
“requested_pod_duration”: 60
}
],
“success”: true
},
“status”: 200,
“headers”: {
“date”: “Mon, 06 May 2024 14:05:12 GMT”,
“vary”: “Accept-Encoding”,
“pragma”: “no-cache”,
“connection”: “Close”,
“content-type”: “application/json; charset=utf-8”,
“cache-control”: “no-store”,
“content-length”: “394”,
“access-control-allow-origin”: “*”,
“access-control-allow-headers”: “Access-Control-Allow-Origin, Accept, Accept-Encoding, Authorization, Content-Length, Content-Type, X-CSRF-Token”,
“access-control-allow-methods”: “POST, GET, OPTIONS, PUT, DELETE, HEAD, PATCH”,
“access-control-expose-headers”: “Access-Control-Allow-Origin, Accept, Accept-Encoding, Authorization, Content-Length, Content-Type, X-CSRF-Token”,
“access-control-allow-credentials”: “true”
}
}

now I would like to add a row to baserow for each of the sitename data. Since I can add a single row, I think of using a loop + add a (base)row. I am stuck in just getting each part of the array separately and make the loop dynamic.
just for example each row should contain each sitename information like: {
“date”: “2024-04-23T00:00:00+00:00”,
“revenue”: 0,
“bid_wons”: 654,
“sitename”: “Web”,
“impressions”: 0,
“bid_requests”: 27673,
“bid_responses”: 8546,
“endpoint_requests”: 324,
“delivered_pod_duration”: 0,
“requested_pod_duration”: 60
}
I guess a code block will work to parse the array but I am unable to write the right code

here my flow so far:

many thanks

Hello @pablo_adops , Welcome to the community :wave:,

You’re on the right track! Please select data as the input for the loop step and test it. It will return one row from the array as output. This output can then be used to map data with the baserow step. Once you’ve completed mapping the entire flow, simply click the Test Flow button. This will parse all items of the array in the loop and execute the baserow step for each one. You don’t have to use the code step to parse the array, as the loop step will automatically parse it with each iteration.

1 Like

hi @kishanprmr ,
thanks for the quick reply.
so impressed that the solution was so simple!! Using just the Loop is so effective.
In the loop I inserted just the baserow-create a row and I got it.
Many many thanks

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.