SuccessTemplate - to display specific specific fields

Hello,

I setup an integration to call Google Geocode API and then an action.
In the action configuration, I have the below translation map and struggling with setting up the successTemplate. I am trying to follow the examples listed in the below documentation page and it does not work. I want to have both county and state fields in the results. I can just see one of them but not both.

{
"translationMap": {
"county": "$.results[0].address_components[2]",
"state": "$.results[0].address_components[3]"
},
"translationMapDefaults": {},
"successTemplate": "${state}, ${county}"
}

link to documentation:

Hi thon,

When you look at the results of "9. Resolve translation map" in test mode are you seeing that county and state are being set to the expected values?

It also might help if you provided an example of the output from step 8, execution. Feel free to anonymize anything sensitive, but keep the shape of the data the same.

--Jason

Hi Jason, Thanks for your response. Here are the details:

Step#9:

{
"rawResult": "{\n "results" : [ {\n "address_components" : [ {\n "long_name" : "33142",\n "short_name" : "33142",\n "types" : [ "postal_code" ]\n }, {\n "long_name" : "Miami",\n "short_name" : "Miami",\n "types" : [ "locality", "political" ]\n }, {\n "long_name" : "Miami-Dade County",\n "short_name" : "Miami-Dade County",\n "types" : [ "administrative_area_level_2", "political" ]\n }, {\n "long_name" : "Florida",\n "short_name" : "FL",\n "types" : [ "administrative_area_level_1", "political" ]\n }, {\n "long_name" : "United States",\n "short_name" : "US",\n "types" : [ "country", "political" ]\n } ],\n "formatted_address" : "Miami, FL 33142, USA",\n "geometry" : {\n "bounds" : {\n "northeast" : {\n "lat" : 25.831979,\n "lng" : -80.2150489\n },\n "southwest" : {\n "lat" : 25.79223,\n "lng" : -80.2670359\n }\n },\n "location" : {\n "lat" : 25.8127791,\n "lng" : -80.2377078\n },\n "location_type" : "APPROXIMATE",\n "viewport" : {\n "northeast" : {\n "lat" : 25.831979,\n "lng" : -80.2150489\n },\n "southwest" : {\n "lat" : 25.79223,\n "lng" : -80.2670359\n }\n }\n },\n "place_id" : "ChIJY4q-GNKw2YgRhC4gBeXod5E",\n "postcode_localities" : [ "Brownsville", "Hialeah", "Liberty Square", "Miami", "Miami Springs" ],\n "types" : [ "postal_code" ]\n } ],\n "status" : "OK"\n}",
"county": "{\n "long_name" : "Miami-Dade County",\n "short_name" : "Miami-Dade County",\n "types" : [ "administrative_area_level_2", "political" ]\n}"
}

Step#8:

{
"results": [
{
"address_components": [
{
"long_name": "33142",
"short_name": "33142",
"types": [
"postal_code"
]
},
{
"long_name": "Miami",
"short_name": "Miami",
"types": [
"locality",
"political"
]
},
{
"long_name": "Miami-Dade County",
"short_name": "Miami-Dade County",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "Florida",
"short_name": "FL",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "United States",
"short_name": "US",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Miami, FL 33142, USA",
"geometry": {
"bounds": {
"northeast": {
"lat": 25.831979,
"lng": -80.2150489
},
"southwest": {
"lat": 25.79223,
"lng": -80.2670359
}
},
"location": {
"lat": 25.8127791,
"lng": -80.2377078
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 25.831979,
"lng": -80.2150489
},
"southwest": {
"lat": 25.79223,
"lng": -80.2670359
}
}
},
"place_id": "ChIJY4q-GNKw2YgRhC4gBeXod5E",
"postcode_localities": [
"Brownsville",
"Hialeah",
"Liberty Square",
"Miami",
"Miami Springs"
],
"types": [
"postal_code"
]
}
],
"status": "OK"
}

Hi Thon,

The issue is that you are outputting two JSON objects next to each other, instead of a single JSON object that contains everything you need. You can solve this by setting your successTemplate to something like this:

"successTemplate": "{ \"state\" : ${state}, \"county\" : ${county} }"

--Jason

2 Likes

Thanks Jason. It shows up as invalid json. Here is the error it throws:
Parse error on line 7:
...ccessTemplate": "{ "state" : ${state}, "
-----------------------^
Expecting 'EOF', '}', ':', ',', ']', got 'undefined'

Here is what I tried:

{
"translationMap": {
"county": "$.results[0].address_components[2]",
"state": "$.results[0].address_components[3]"
},
"translationMapDefaults": {},
"successTemplate": "{ "state" : ${state}, "county" : ${county} }"
}

Sorry thon, I forgot to use the "Preformatted" button </> on my example, so it hid some slashes. I edited that post, so try that again.

--Jason

1 Like

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