---
title: "Creates a geofence"
method: POST
path: "/geofences/v2"
tags: ["Geofences"]
---

# Creates a geofence

`POST /geofences/v2`

One can specify a geofence as a circle, as a polygon or as POI (Point of Interest). One can also
assign a name and a description to each geofence to help identify them.

Circle
---

Specify coordinates of the center point of the circle and a radius in
meters.

```json
    {
      "name": "Home",
      "type": "circle",
      "definition": {
        "center": {
          "lat": 52.5308398,
          "lng": 13.38490035
        },
        "radius": 100
      },
      "description": "Small area around my house."
    }
```

Polygon
---

Specify an array of points. A minimum of three points is required.

*NOTE: If the array of points does not describe a closed polygon, the polygon is
automatically closed between the last and first points.*

```json
    {
      "name": "Work",
      "type": "polygon",
      "definition": {
        "points": [{
          "lat": 52.5308398,
          "lng": 13.38490035
        }, {
          "lat": 52.530443,
          "lng": 13.38482003
        }, {
          "lat": 52.5308298,
          "lng": 13.38492235
        }]
      },
      "description": "The area around work."
    }
```

Indoor geofence
---

Circular and polygonal geofences can be both outdoors and indoors.
To create a `circular` `indoor` geofence, add the `floor` property to the request body.

```json
    {
      "name": "Office indoor",
      "type": "circle",
      "definition": {
        "center": {
          "lat": 52.5308398,
          "lng": 13.38490035
        },
        "radius": 20,
        "floor": {
          "level": 2,
          "id": "DM_1234",
          "name": "Office floor 2"
        }
      },
      "description": "Floor 2 of the office."
    }

```

POI geofence
---

Specify location details of a POI geofence for its initial creation.

After the POI geofence has been created, it will need to be trained.
The POI geofence boundary is defined using radio measurements.
The POI geofence is trained using a telemetry 
that a device has ingested while being at this desired point of interest.

For a trained POI geofence, an associated device is considered to be inside the 
geofence when the radio measurements of the device-ingested telemetry and 
the training data match.

```json
    {
      "name": "POI room in the office",
      "type": "poi",
      "definition": {
        "location": {
          "room": ROOM_201,
          "address": Invalidenstrasse 116,
          "country": Germany,
          "position": {
            "lat": 52.5308398,
            "lng": 13.38490035
          }
        },
        "floor": {
          "level": 2,
          "id": "DM_1234",
          "name": "Office floor 2"
        }
      },
      "description": "A room where goods should be delivered."
    }
```

Successful requests have the HTTP status 201 and the response body provides
the ID of the created geofence.

## Request body

- union
  - object
    - `definition` object, required — An object that defines the area of a circular geofence
      - `center` object, required — The coordinates of the center point of the circle.
        - `lat` number, required — Latitude in WGS-84 format, decimal representation ranging from -90 to 90.
        - `lng` number, required — Longitude in WGS-84 format, decimal representation ranging from -180 to 180.
      - `floor` object — The building associated with the geofence
        - `id` string, required — The building ID
        - `level` number — The floor of the geofence in integer format
        - `name` string, required — The building name
      - `radius` number, required — The radius of the circle in meters.
    - `description` string — A description of the area that the geofence encloses and the purpose of the geofence.
    - `name` string — A human-readable name of the geofence.
    - `type` 'circle', required — The geofence type.
  - object
    - `definition` object, required — An object that defines the area of a polygonal geofence.
      - `floor` object — The building associated with the geofence
        - `id` string, required — The building ID
        - `level` number — The floor of the geofence in integer format
        - `name` string, required — The building name
      - `points` object[], required — An array of points that define the polygon. A minimum of three and a maximum of ten points is required.
        - `lat` number, required — Latitude in WGS-84 format, decimal representation ranging from -90 to 90.
        - `lng` number, required — Longitude in WGS-84 format, decimal representation ranging from -180 to 180.
    - `description` string — A description of the area that the geofence encloses and the purpose of the geofence.
    - `name` string — A human-readable name of the geofence.
    - `type` 'polygon', required — The geofence type.
  - object
    - `definition` object — An object that defines the area of a POI geofence.
      - `floor` object — The building associated with the geofence
        - `id` string, required — The building ID
        - `level` number — The floor of the geofence in integer format
        - `name` string, required — The building name
      - `location` object — Details of the geofence location
        - `address` string — Address
        - `country` string — Country
        - `position` object — Coordinates for visualization purposes
          - `lat` number, required — Latitude in WGS-84 format, decimal representation ranging from -90 to 90.
          - `lng` number, required — Longitude in WGS-84 format, decimal representation ranging from -180 to 180.
        - `room` string — The room ID
    - `description` string — A description of the area that the geofence encloses and the purpose of the geofence.
    - `name` string — A human-readable name of the geofence.
    - `type` 'poi', required — The geofence type.

## Response `201`

Created

The geofence was successfully created.

- object
  - `id` string, uuid, required — Geofence ID
  - `message` string

## Other responses

- `400` — Bad request The request object is in an incorrect format or has values that are invalid or out of range. If available, further error details are provided in the response body.
- `401` — Unauthorized The request did not provide correct authentication details
- `403` — Forbidden The account does not have the correct privileges

---

[API](https://skmtc.net/here/apis/tracking.md) · [All operations](https://skmtc.net/here/apis/tracking/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/here/tracking/versions/efa162f7023c/schema)
