Add new fence to a project

Service version: 1
Last edit: 2022.09.01

Purpose

The Add new fence to a project endpoint creates a new fence and automatically links it to a single project.

  • The easiest way to add a new fence is by adding a new one to a project.
  • Instead of listing fences in the request body, a new fence can be added to the single project selected in the request URL.

Request data

HTTPS method: POST

  • Constants and parameters enclosed in curly brackets { } must be replaced with their values.
  • Please see the following Request parameters section with the required and optional parameters tables for their values. The generic request format is as follows.

URL request format

post
URL request format
https://{baseURL}/geofencing/{versionNumber}/projects/{projectId}/fence?key={Your_API_Key}&adminKey={Your_Admin_Key}

curl command request format

post
curl command request format
1curl -XPOST -H "Content-type: application/json" -d '{
2 "name": "fence_name",
3 "type": "Feature",
4 "geometry": {
5 "radius": radius_in_meters,
6 "type": "Point",
7 "shapeType": "shape_type",
8 "coordinates": [longitude, latitude]
9 },
10 "properties": { //Optional
11 "key": "value"
12 }
13}' 'https://{baseURL}/geofencing/{versionNumber}/projects/{projectId}/fence?key={Your_API_Key}&adminKey={Your_Admin_Key}'

POST request body format

post
Request body format - JSON
1{
2 "name": "fence_name",
3 "type": "Feature",
4 "geometry": {
5 "radius": radius_in_meters,
6 "type": "Point",
7 "shapeType": "shape_type",
8 "coordinates": ["longitude", "latitude"]
9 },
10 "properties": {
11 "key": "value"
12 }
13}

Request parameters

The following table describes the parameters that can be used in a request.

  • Required parameters must be used or the call will fail.
  • Optional parameters may be used.
  • The order of request parameters is not important.

Required parameters

Description

baseURL
string

The base URL for calling the API.
Value: api.tomtom.com

versionNumber
string

Service version number.
Value: 1

key
string

An API Key valid for the requested service.
Value: API Key

adminKey
string

Admin Key valid for provided API Key.
Value: A valid Admin Key.

projectId
string

The project id to create a fence for.
Value: UUID

Optional parameters

Description

showGeoJson
boolean

If set to true, the output contains a representation of a custom fence shape.
For fences that are defined as GeoJSON, this parameter changes nothing.
Default value: false
Other value: true

Response data

Response body

Response body format - JSON
1{
2 "name": "fence_name",
3 "id": "fence_id",
4 "type": "Feature",
5 "geometry": {
6 "radius": radius_in_meters,
7 "type": "Point",
8 "shapeType": "shape_type",
9 "coordinates": ["longitude, latitude"]
10 },
11 "properties": {
12 "key": "value"
13 }
14}

Response fields

The following table describes all of the response fields.

Primary fields

Description

name
string

The name of the fence.

id
string

The UUID of the fence.

type
string

In the current version it is always "Feature".

geometry
object

An object that describes fence geometry. See the Custom fence shapes section.

properties
object

(Optional) An object containing user-defined properties of the fence. Its content varies between fences.

Response codes

Code

Meaning & possible causes

201

Created

400

Bad request:

  • Fence with the given name already exists.
  • Fence geometry is invalid or not supported.

403

Forbidden:

  • The provided Admin Key is invalid.
  • The Admin Key is missing.

Example

Add a new fence to a project

URL request example

post
URL request example
https://api.tomtom.com/geofencing/1/projects/44de824d-c368-46cf-a234-a6792682dfd6/fence?key=Your_API_Key&adminKey=Your_Admin_Key

POST request body example

post
POST request body example - JSON
1{
2 "name": "No-fly zone 23",
3 "type": "Feature",
4 "geometry": {
5 "radius": 75,
6 "type": "Point",
7 "shapeType": "Circle",
8 "coordinates": [-67.137343, 45.137451]
9 },
10 "properties": {
11 "maxSpeedKmh": 70
12 }
13}

Response body example

Response body example - JSON
1{
2 "name": "No-fly zone 23",
3 "id": "aaab6d78-1738-45bd-a78b-ff3a7ba839f3",
4 "type": "Feature",
5 "geometry": {
6 "radius": 75,
7 "type": "Point",
8 "shapeType": "Circle",
9 "coordinates": [-67.137343, 45.137451]
10 },
11 "properties": {
12 "maxSpeedKmh": 70
13 }
14}