Open Places API

Example

Call the Places API from Node.js.

Keep the API key in your backend environment, call GET /v1/places with fetch, and handle error codes before using the results.

Node.js example.

const apiKey = process.env.OPEN_PLACES_API_KEY;

if (!apiKey) throw new Error("OPEN_PLACES_API_KEY is required");

const url = new URL("https://api.openplacesapi.com/v1/places");
url.search = new URLSearchParams({
  q: "coffee",
  lat: "40.7128",
  lon: "-74.0060",
  radius_mi: "25",
  limit: "10",
  min_confidence: "0.85"
}).toString();

const response = await fetch(url, {
  headers: {
    Authorization: `Bearer ${apiKey}`
  }
});

const body = await response.json();

if (!response.ok) {
  throw new Error(body?.error?.code || "places_api_error");
}

for (const place of body.results) {
  console.log({
    name: place.name,
    category: place.categories?.[0],
    distance_mi: place.distance_mi,
    confidence: place.confidence,
    phone: place.phone,
    website: place.website
  });
}