Create new fence, assign to multiple projects

Service version: 1
Last edit: 2022.09.01

Purpose

This endpoint creates a new fence and assigns it to multiple projects.

Request data

HTTPS method: POST

  • Constants and parameters enclosed in curly brackets &#123 } 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

https://{baseURL}/geofencing/{versionNumber}/fences/fence?key={Your_API_Key}&adminKey={Your_Admin_Key}

curl command request format

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

POST request body

1{
2 "name": "fence_name",
3 "type": "Feature",
4 "projects": ["project_1_id", ...],
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}

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: Your valid API Key.

adminKey
string

A valid Admin Key.


Value: Your valid Admin Key.

Optional parameters

Description

showGeoJson
boolean

If set to true, the output contains a GeoJSON 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

1{
2 "name": "fence_name",
3 "id": "fence_id",
4 "type": "Feature",
5 "projects": [project_1_id, ... , project_N_id],
6 "geometry": {
7 "radius": radius_in_meters,
8 "type": "Point",
9 "shapeType": "shape_type",
10 "coordinates": [longitude, latitude]
11 },
12 "properties": {
13 "key:" "value"
14 }
15}

Response fields

The following data tables describe all of the fields that can appear in a response. Fields are listed by the response section they belong to and in the order that they appear in the response.

Primary fields

Field

Description
name
string
The name of the fence.
id
string
The UUID of the fence.
type
string
In the current version its always "Feature".
projects
array
The list of projects the fence was assigned to.
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.

projects array

Field

Description
id
string
The UUID of a project.
name
string
The name of a project.

Response codes

Code

Meaning & possible causes

201Created
400

Bad request:

  • Fence with the given name already exists.
  • Fence geometry is invalid or not supported.
  • At least one project has to be defined for a new fence.
403

Forbidden:

  • Provided Admin Key is invalid.
  • Admin Key is missing.

Example

Create a new fence and assign it to multiple projects.

URL request example

https://api.tomtom.com/geofencing/1/fences/fence?key={Your_API_Key}&adminKey={Your_Admin_Key}

POST request body example

1{
2 "name": "No-fly zone 23",
3 "type": "Feature",
4 "projects": [
5 "131db271-752e-4462-bd7a-ac948864110e",
6 "36188f87-03ea-4fd4-b606-68d28f781365"
7 ],
8 "geometry": {
9 "radius": 75,
10 "type": "Point",
11 "shapeType": "Circle",
12 "coordinates": [-67.137343, 45.137451]
13 },
14 "properties": {
15 "maxSpeedKmh": 70
16 }
17}

Response body example

1{
2 "name": "No-fly zone 23",
3 "id": "aaab6d78-1738-45bd-a78b-ff3a7ba839f3",
4 "type": "Feature",
5 "projects": [
6 "131db271-752e-4462-bd7a-ac948864110e",
7 "36188f87-03ea-4fd4-b606-68d28f781365"
8 ],
9 "geometry": {
10 "radius": 75,
11 "type": "Point",
12 "shapeType": "Circle",
13 "coordinates": [-67.137343, 45.137451]
14 },
15 "properties": {
16 "maxSpeedKmh": 70
17 }
18}