# Places errors

A request either answers with places or fails as a whole. A location that cannot be read is an error, never a guess.

Places uses the one [error shape](https://millionshort.com/docs/errors#the-error-shape) every endpoint uses. No error is charged.

## Location errors

Both are `400 INVALID_PARAM`, told apart by `error.details.reason`.

| `details.reason` | When | Try next |
|---|---|---|
| `location_required` | The request names a kind of place and says nowhere to look | Send `near`, `lat` with `lng`, `bbox`, or one of the other [ways to say where](https://millionshort.com/docs/places/parameters#where) |
| `location_not_found` | The place named, or the IP address, is not one we can place. `details.param` says which field: see below | Depends on the field |

| `details.param` | What was not found | Try next |
|---|---|---|
| `near` | The place named in `near` | Add the state, province or country; try the city alone; or send `lat` and `lng` |
| `neighbourhood` | The neighbourhood, with its `city` if one was sent | Send `city` with it; try the city alone; or send `lat` and `lng` |
| `city` | The `city` (with its `region`) used as the location | Check the spelling and the region code; or send `near` with the country |
| `ip` | The IP address could not be placed in a city | Ask the user where they are; send `near`, or `lat` and `lng` |
| `near_me` | The address the call came from could not be placed, or is on a private network | The same |

```json
{
  "error": {
    "code": "INVALID_PARAM",
    "message": "We could not find the place named in near. Try a city, a neighbourhood with its city, a postcode or a street address, or send lat and lng.",
    "retry_after_seconds": null,
    "details": { "param": "near", "reason": "location_not_found" }
  },
  "request_id": "req_01JD0PLACES9X3K5N7B"
}
```

A place is never guessed. A name that is qualified ("Springfield, OR") and cannot be found there is `location_not_found`, not a Springfield somewhere else. The address a request comes from is used only when `near_me` says so, and an address that cannot be placed is an error, not a default city.

A search that reads its location and finds no places is not an error: it answers `200` with an empty `results`.

## Request errors

| Status and code | When |
|---|---|
| `400 INVALID_PARAM` | A field the API does not take; none of `query`, `category` and `brand`; more than one of `near`, `lat` with `lng`, `bbox`, `ip`, `near_me` and `neighbourhood`; `lat` without `lng`; `radius_m` with `bbox` or with no location; a category we do not have; an `ip` that is not one public address; a `fields` entry that is not a place field; a value out of range or of the wrong type; and the two location errors above |
| `401 AUTH_MISSING_KEY`, `401 AUTH_INVALID_KEY` | No `Authorization` header, or a key that is malformed, revoked or expired |
| `403 QUOTA_EXCEEDED` | The key's monthly cap does not cover the call |
| `429 INSUFFICIENT_CREDITS` | The balance does not cover the `limit` asked for |
| `429 RATE_LIMITED` | The plan's requests a minute, or its searches in flight |
| `429 CAPACITY` | We have no room for this call right now. Retry after `retry_after_seconds` |
| `502 SEARCH_UNAVAILABLE` | Places could not be served right now. Retry after `retry_after_seconds` |

[Errors](https://millionshort.com/docs/errors) says which of these are worth retrying.

## Warnings

A `200` can carry `warnings`: `hours_coverage` whenever `open_now` is sent, because most places have no hours on record and open places can be missing from the list. See [Opening hours and open_now](https://millionshort.com/docs/places/guides#opening-hours-and-open_now).

`sort_not_applied` says `"sort": "distance"` had no point to measure from, because the location is an area such as a city. The places are in order of relevance. Send `lat` with `lng`, or name a neighbourhood or an address.
