Skip to content
GuidesBlogPlaygroundDashboard

Fetch multiple features by type and ID

client.elements.batch(ElementBatchParams { elements } body, RequestOptionsoptions?): FeatureCollection { features, type }
POST/api/v1/features/batch

Fetch multiple features by type and ID

ParametersExpand Collapse
body: ElementBatchParams { elements }
elements: Array<Element>

Array of element references to fetch

id: number

OSM element ID

type: "node" | "way" | "relation"

OSM element type

One of the following:
"node"
"way"
"relation"
ReturnsExpand Collapse
FeatureCollection { features, type }

GeoJSON FeatureCollection (RFC 7946). For paginated endpoints, metadata is returned in HTTP response headers rather than the body:

Header Description
X-Limit Requested result limit
X-Has-More true if more results exist
X-Next-Cursor Opaque cursor for next page (cursor pagination)
X-Next-Offset Numeric offset for next page (offset pagination)
Link RFC 8288 rel="next" link to the next page

Content-Type is application/geo+json.

features: Array<GeoJsonFeature { geometry, properties, type, id } >

Array of GeoJSON Feature objects

geometry: GeoJsonGeometry { coordinates, type }

GeoJSON Geometry object per RFC 7946. Coordinates use [longitude, latitude] order. 3D coordinates [lng, lat, elevation] are used for elevation endpoints.

coordinates: Array<number> | Array<Array<number>> | Array<Array<Array<number>>> | Array<Array<Array<Array<number>>>>

Coordinates array. Nesting depth varies by geometry type: Point = [lng, lat], LineString = [[lng, lat], ...], Polygon = [[[lng, lat], ...], ...], etc.

One of the following:
Array<number>
Array<Array<number>>
Array<Array<Array<number>>>
Array<Array<Array<Array<number>>>>
type: "Point" | "LineString" | "Polygon" | 3 more

Geometry type

One of the following:
"Point"
"LineString"
"Polygon"
"MultiPoint"
"MultiLineString"
"MultiPolygon"
properties: Record<string, unknown>

OSM tags flattened as key-value pairs, plus @type (node/way/relation) and @id (OSM ID) metadata fields. May include distance_m for proximity queries.

type: "Feature"

Always Feature

id?: string

Compound identifier in type/osm_id format

type: "FeatureCollection"

Always FeatureCollection

Fetch multiple features by type and ID

import Plaza from '@plazafyi/sdk';

const client = new Plaza({
  apiKey: process.env['PLAZA_API_KEY'], // This is the default and can be omitted
});

const featureCollection = await client.elements.batch({
  elements: [
    { id: 21154906, type: 'node' },
    { id: 4589123, type: 'way' },
  ],
});

console.log(featureCollection.features);
{
  "features": [
    {
      "geometry": {
        "coordinates": [
          2.3522,
          48.8566
        ],
        "type": "Point"
      },
      "properties": {
        "@id": "bar",
        "@type": "bar",
        "amenity": "bar",
        "cuisine": "bar",
        "name": "bar"
      },
      "type": "Feature",
      "id": "node/21154906"
    }
  ],
  "type": "FeatureCollection"
}
Returns Examples
{
  "features": [
    {
      "geometry": {
        "coordinates": [
          2.3522,
          48.8566
        ],
        "type": "Point"
      },
      "properties": {
        "@id": "bar",
        "@type": "bar",
        "amenity": "bar",
        "cuisine": "bar",
        "name": "bar"
      },
      "type": "Feature",
      "id": "node/21154906"
    }
  ],
  "type": "FeatureCollection"
}