Extracting fields from bundles with varying bundle quantities

What are you trying to achieve?

I’m trying to extract some custom fields from a Square account using the call API module. I’ve got the data coming through using an API call but it’s the processing afterwards which I’m struggling with.

My Square API produces a bundle for each of my custom field data elements in Square (see attachment - Output from Square API.png). However, the number of custom fields returned may vary from 0 - 10 depending on what’s stored for each customer. For instance, a Square customer may have ticked a subscribe button or that they agree to T&C etc, or may have not… I just don’t know.

Lastly, if the output from Square is not consistent, how can I guarantee the values mapped into the Data Store are in the correct fields? Do I need to form the custom field data into a JSON package first then map that to the data store?

Steps taken so far

So far I’ve got the data coming out of the Square API call and I’ve tried to map the contents to the data store but cannot see how to get access to the Body of the API bundle (see 'How do I access the body… image) to aggregate the contents into a form I can store in my Data Store?

Even then, I’m not sure if aggregating is the right next step. I can’t repeat through the bundles as I don’t know how many will be returned from Square.

Screenshots: scenario setup, module configuration, errors




I think you need to add a Parse JSON module after the Square Make an API call step, that should allow you to use the elements in the JSON body.

Thanks for your help.

After a bit of research, I think I need to use get(map()) but I’m not quite there yet.

Any further help would be appreciated. Thanks.

Hello @AlT,
In the Make get() and map() are powerful while you handle collection/array.
So before directly jumping to implementation, I recommend you to see this course if you’re using it the first time.
Specific course: Using get() and map() functions

Full course: 🟣 Make Academy: Course Overview


:bulb:P.S.: Always search first in the community. If this answer is helpful, mark it as a solution :white_check_mark: and :+1: Need expert help or have questions? Contact or comment below! :point_down:

Hi,

Thanks. This is where I’ve got this info from. I’ve gone through the intermediate academy course content but I still don’t understand how to apply it here.

Hello @AlT,
As per the shared images, I can see that Square response itself is a collection and within are multiple elements of the array under the Body ⇒ custom_attributes.
Don’t need to use Array Aggregator here you can directly apply an iterator or get/map to go for further process.

Now about data inconsistency.
Use key OR name field I think it’s always going to be unique with all custom attributes across different clients. Just for confirmation cross-check it with a couple of multiple clients.

The first thing is do you need only one(specific) custom field from that array or all of them?

If one then directly use get(map()).
If all of then then use iterator use this as source of it Body ⇒ custom_attributes.
Then do further process.

I hope this helps.

:+1:

1 Like

Thanks. I’ll give this a go.

As a result of @dilipborad’s help, I’m now able to extract the data I need from the Square API call but have experienced another issues beyond this.

This is how I’ve made the variables from the API. (Note: There are 9 custom variables I can get from the API in total. I cannot guarantee each call will provide all 9, but, in this instance there are.)

There are two showing in the aggregator: ‘Gender’ & ‘Would you like to receive our newsletter’ (a terrible variable name, I know, but I have no control over this)

When I try to aggregate the variables I’ve created I cannot aggregate them because they’re not showing in aggregated fields for me to click.

As you can see, it only shows the first two elements and not all 9 which are produced by the previous module. Is this typical?

How can I get it to aggregate all of them produced by the previous set multiple variables module?