Saving Google Places API nested array value to attribute

(Kurt Anderson) #1

I’m using Google’s Places API using the Find Location template provided by FlowXO. After the user provides the place name and location, the Google Places API return’s JSON and a card set is created from the results. Here is the JSON:

Creating attributes from objects in the JSON is fairly straight forward, until those values are stored within an array, at which point I cannot figure out what format I should use to traverse the array to retrieve the values. For example, how would I get the value for street number, long name?

If anyone has solved this problem, I’d love to know how it’s done!

Cheers!

(Andrew Karanda) #2

Attributes need to be look like:

Attribute name | Attribute Data

street_number | {{get_details_for_place_1.data__results__address_components__0__long_name}}

For example:
If you need “street name” attributes look like:

Attribute name | Attribute Data

street_name | {{get_details_for_place_1.data__results__address_components__1__long_name}}

1 Like
(Kurt Anderson) #3

Hey Andrew,

Thanks for the quick response! I cut and pasted your code for street number into FlowXO to pull the attribute data, but it did not grab the data, unfortunately. Any insight would be amazingly helpful.

I would very much like to understand how I can educate myself on the particulars of the syntax of these types of requests…can you point me to an online resource where I can learn this myself?

In particular, I didn’t pick up when I initially looked at the code snippet you sent, that there is the use of both single underscore and double underscores within the snippet. I thought this might have been a mistake, but now I realize that it was intentional. Do I understand correctly?

Thanks in advance!

Cheers

(Kurt Anderson) #4

An update: I got the attribute to populate, after staring at the syntax for a while, I realized that the code snippet you provided had ‘results’ plural, rather than ‘result’ singular, which I changed and is now working! Woot!

I’m still interested in understanding the syntax, naturally, as I will be using JSON, API’s, and FlowXO extensively. But happily, much google searching found this article:

https://support.flowxo.com/article/143-data-outputs

Which answered my questions quite nicely!

1 Like