Using Data from API - Accessing Data

Dear All,

I am using an api to search for address data. The Data I get back looks as follows:

{
  "info": {
"statuscode": 0,
"copyright": {
  "text": "© 2020 MapQuest, Inc.",
  "imageUrl": "http://api.mqcdn.com/res/mqlogo.gif",
  "imageAltText": "© 2020 MapQuest, Inc."
},
"messages": []
  },
  "options": {
"maxResults": 4,
"thumbMaps": true,
"ignoreLatLngInput": false
  },
  "results": [
{
  "providedLocation": {
    "location": "Kaiserstrasse, Frankfurt"
  },
  "locations": [
    {
      "street": "Kaiserstraße",
      "adminArea5": "Frankfurt",
      "adminArea5Type": "City",
      "adminArea1": "DE",
      "adminArea1Type": "Country",
      "postalCode": "60311",
      "geocodeQuality": "STREET",
      "latLng": {
        "lat": 50.110525,
        "lng": 8.675396
      },
      "mapUrl": "http://open.mapquestapi.com/staticmap/v5/map?key=U1tglbAv9Ib2uvRHK407DFON51co2FD1&type=map&size=225,160&locations=50.1105246,8.6753957|marker-sm-50318A-1&scalebar=true&zoom=15&rand=-1278117604"
    },
    {
      "street": "Kaiserstraße",
      "adminArea5": "Kelsterbach",
      "adminArea5Type": "City",
      "adminArea1": "DE",
      "adminArea1Type": "Country",
      "postalCode": "60329",
      "geocodeQuality": "STREET",
      "latLng": {
        "lat": 50.108349,
        "lng": 8.668294
      },
      "mapUrl": "http://open.mapquestapi.com/staticmap/v5/map?key=U1tglbAv9Ib2uvRHK407DFON51co2FD1&type=map&size=225,160&locations=50.1083489,8.6682939|marker-sm-50318A-3&scalebar=true&zoom=15&rand=1243864394"
    }
  ]
}
  ]
}

I would like to work with the locations inside results. Somehow I am not able to access the locations.

grafik

My logic is fairly Basic:
grafik

data.OpenMapsApi1 does not allow me to access anything like data.OpenMapsApi1.locations or data.OpenMapsApi1[0] …

Any idea, what I am doing wrong?

Thanks in advance,
Tobias

Have you checked the debugger for what you have in the Data variable after setting it? You can also use ENCODE_JSON() to check that the request response or the data variable actually has the data it should (and the use e.g. Alert of Paragraph to show it). (Also adding an Alert after failure of Adresse suchen might be a good addition)

If the Data variable has the data it should, I don’t see a reason why you couldn’t access the data. data.OpenMapsApi1[0].locations[0]should allow you to see the first location of the first result.

Thank you very much for responding swiftly.

Sorry for not mentioning. I already did the alert thingy:
The weired thing I noticed: while I usually get [object] or [object][object] in case I am not using ENCODE_JSON with this API I do not need ENCODE_JSON(data.OpenMapsApi1) and the type seems to be “string” resp. “text”.

With regards to setting the data variable, I tried both ways output of previous node (works) and setting the variable (does NOT work) as follows:


not working:
image
working:
image

this

results in (I noticed, that it is not picking up my data scheme):

my data scheme for get collection:

I think I am missing something fairly stupid on my side - but can’t figure what.

Hi,

I am truely not sure what I did (probably deleting a key that was not existing in the data from the response schema), but It is working now!

I can repeat with data.OpenMapApi1[0].locations and access all data via current.key
Maybe I was working too late yesterday evening :slight_smile:

Thanks a lot
Tobias

1 Like