Google Maps API

Hello,
I am trying to execute a Data Action that queries the Google Maps API and returns the CountryCode. The problem I have is that it returns a value for the assigned Code, but with an error.

Request:

{
"requestUrlTemplate": "https://maps.googleapis.com/maps/api/geocode/json?address=${input.address}&key=XXXXX",
"requestType": "GET",
"headers": {},
"requestTemplate": "${input.rawRequest}"
}

Response:

{
"translationMap": {
"CountryCode": "$.results[0].address_components[?(@.types[0] == 'country')].short_name"
},
"translationMapDefaults": {},
"successTemplate": "${CountryCode}"
}

Input:

{
"type": "object",
"required": [
"address"
],
"properties": {
"address": {
"type": "string"
}
},
"additionalProperties": true
}

Output:

{
"type": "object",
"properties": {
"CountryCode": {
"type": "string"
}
},
"additionalProperties": true
}

Output transformation returns correct value but still error

{
"message": "JSON failed output schema validation for the following reasons: instance type (array) does not match any allowed primitive type (allowed: ["object"])",
"code": "invalid.schema",
"status": 400,
"messageParams": {},
"contextId": "6a54d6be-3dfb-4462-8f54-1946146609d6",
"details": [
{
"errorCode": "ACTION.PROCESSING"
}
],
"errors": []
}

What could be causing this error?
Thanks!

Your output schema is configured to be an object with a CountryCode in it, so something like:
{
"CountryCode" : "DE"
}

However, the action is returning an array with a CountryCode in it:
[
"CountryCode" : "DE"
]

Note that {} is for an object, but [] is for an array.

You should be able to update your output contract to get this resolved.

--Jason

Hi, Thank you very much for qucik replay.
I cannot find correct output schema. Anything I tried always give same error.
Maybe that will help, below raw API Response.

{
"results": [
{
"address_components": [
{
"long_name": "Berlin",
"short_name": "Berlin",
"types": [
"locality",
"political"
]
},
{
"long_name": "Kreisfreie Stadt Berlin",
"short_name": "Kreisfreie Stadt Berlin",
"types": [
"administrative_area_level_3",
"political"
]
},
{
"long_name": "Berlin",
"short_name": "BE",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Germany",
"short_name": "DE",
"types": [
"country",
"political"
]
}
],
"formatted_address": "Berlin, Germany",
"geometry": {
"bounds": {
"northeast": {
"lat": 52.6754542,
"lng": 13.7611175
},
"southwest": {
"lat": 52.338234,
"lng": 13.088346
}
},
"location": {
"lat": 52.52000659999999,
"lng": 13.404954
},
"location_type": "APPROXIMATE",
"viewport": {
"northeast": {
"lat": 52.6754542,
"lng": 13.7611175
},
"southwest": {
"lat": 52.338234,
"lng": 13.088346
}
}
},
"place_id": "ChIJAVkDPzdOqEcRcDteW0YgIQQ",
"types": [
"locality",
"political"
]
}
],
"status": "OK"
}

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