Unexpected behavior when passing lat/lng AND partial address through bulk API

The documentation for the API notes that “each query must have non-blank values for at least one of the following combinations”:

  • query.latitude + query.longitude
  • query.street_address + query.city + query.region + query.postal_code + query.iso_country_code

But when submitting a bulk query the API returns a 400 status code error if city and postal code are missing, even if there is a valid lat/lng.

Given that placekey is checking the lat/lng first, should it fail when a partial address is used?

Thanks in advance for any thoughts/guidance!

Example that returns 400 status_code (same result with NA or NULL in city and postal_code:

response <- POST('https://api.placekey.io/v1/placekeys',
                 body = list(queries = list(
                   list(
                     latitude = 35.97922,
                     longitude = -78.78797,
                     street_address = '302 PATTERSON RD',
                     city = '',
                     region = 'NC',
                     postal_code = '',
                     iso_country_code = 'US'
                   ),
                   list(
                     latitude = 35.95072,
                     longitude = -78.95743,
                     street_address = '3608 WESTOVER RD',
                     city = '',
                     region = 'NC',
                     postal_code = '',
                     iso_country_code = 'US'
                   )
                 )
                 ),
                 add_headers(apikey = Sys.getenv("PLACEKEY_SECRET")),
                 encode = 'json')

Working version without partial address:

response <- POST('https://api.placekey.io/v1/placekeys',
                 body = list(queries = list(
                   list(
                     latitude = 35.97922,
                     longitude = -78.78797
                   ),
                   list(
                     latitude = 35.95072,
                     longitude = -78.95743
                   )
                 )
                 ),
                 add_headers(apikey = Sys.getenv("PLACEKEY_SECRET")),
                 encode = 'json')

Hi @mtdukes , I’m a bit surprised the Placekey API isn’t handling these types of requests.

I’m wondering if including the blank strings is causing an issue. Could you try the top request again and remove the city and postal_code lines completely (while still including the other partial address info)?

If that works, we would appear to have a workaround. If it does not work, we’ll get in touch with someone to dig in further.

Hey @ryank , thanks for responding. Looks like street_address in the top request example worked in conjunction with latitude and longitude IF city, region and postal_code were either:

  1. NA
  2. Blank ('')
  3. Excluded altogether

It also appears to work if you’ve got lat/lng and some combination of city, region, postal_code and the street_address null/blank/excluded. Not sure if that’s the intended behavior.

I suppose, as a workaround, I can add some logic to check for either a street_address OR a city-region-postal_code group and remove the other so the return is valid?

On potential problem with this workaround is that the API doesn’t return the address encoding portion of the placekey if it doesn’t receive the complete combination of street_address and city-region-postal_code combination, even if it has a latitude and longitude.

Input

response <- httr::RETRY(
  'POST',
  url = "https://api.placekey.io/v1/placekeys",
  body = list(queries = list(
    list(
      #location_name = NA,
      latitude = 36.01564,
      longitude = -78.90254,
      street_address = '1512 RUFFIN ST',
      city = 'Durham',
      region = 'North Carolina',
      postal_code = '27707',
      iso_country_code = 'US'
    ),
    list(
      #location_name = NA,
      latitude = 36.01582,
      longitude = -78.90254,
      street_address = '1514 RUFFIN ST',
      #city = '',
      #region = 'North Carolina',
      #postal_code = '',
      iso_country_code = 'US'
    )
  ),
  options = list(
    strict_name_match = FALSE,
    strict_address_match = FALSE
  )
  ),
  httr::add_headers(apikey = Sys.getenv("PLACEKEY_SECRET")),
  encode = 'json',
  times = 3
) 

content(response)

Output

[[1]]
[[1]]$query_id
[1] "0"

[[1]]$placekey
[1] "226@63f-krk-mp9"


[[2]]
[[2]]$query_id
[1] "1"

[[2]]$placekey
[1] "@63f-krk-mp9"

Hi @mtdukes , I don’t think the Placekey API will infer the city, region/state, and zip if they are missing. If you are in a situation where you have the street_address for your POIs but no city, region, and postal_code, you may need to find another way to get those pieces of info. Fortunately, I would expect most datasets that have street_address would also have the other address components.