Geofence is a virtual perimeter for a real-world geographical area. A geofence can be dynamically generated around a location point with a radius (circle geofence) or with a pre-defined set of boundaries (polygon geofence) for stores, neighborhoods, or even cities.
Every time the end user enters or exits a geofence with a location aware device, events are generated. These events can be used to alert the user or perform actions in the backend.
Base URL
The Roam API is organized around REST. Our API has predictable resource-oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.
https://api.roam.ai/v1/api/geofence
Authentication
Roam API uses API keys to authenticate requests. You can view and manage your API keys in the Roam Dashboard.
Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth. Authentication to the API is performed via a custom header Api-Key. Provide your API key as the value for the header Api-Key
All API requests must be made over HTTPS. Calls made over plain HTTP and API requests without authentication will fail.
Create Geofence
Geofences can be created using the Roam API. They can be created over a circle or a polygon geometry. By default, a geofence is applicable to all the users of a project but can also be restricted to a group of users. Geofences can be configured to be enabled for a specified time interval.
Geofence Types:
Roam allows you to create two geofence geometry types:
Circle
Polygon
Circle Geofence
A circular geofence is the region around a location point defined by a radius. To create a circular geofence, the required body parameters are coordinates, and geometry_radius .
A polygon geofence is the area defined by a set of boundaries forming any shape around a location area. To create a polygon geofence, the required body parameters aregeometry_type andcoordinates.
You can monitor geofence events for a specific user or a list of users by passing user_ids which are generated at the time of creating a user. In the case of a user group, you may pass the group_id. If by default, user_ids and group_ids are not specified, then the geofence is activated for all the users of the project.
Based on the User ID
Pass a user_id under the "user_ids" body parameter. Pass an array ofuser_idsto create a geofence specific to multiple users.
You can create time aware geofences to trigger events between a specific time range. You can do so by passing the date and time as the second and third elements of the array to theis_enabledfield in the body section.
During the specified time interval, the entry and exit events will be triggered. However, outside the time interval, you need to ensure that the"is_enabled" field is set to "false".
Adding a description and metadata can help identify and personalize the geofences while displaying them on a map. You can add this information while creating a geofence or updating a geofence.
Adding tag can help filter geofences easily. This field is optional. When a geofence event is generated, the tag is also sent along with the event.
color_code defines the color of the geofence and how it is displayed on the dashboard. Hex Code for CSS colors should be passed in this field without '#'.
Geofence can be updated using PUT API request along with the geofence endpoint.
The following are the values that can be updated once after the Geofence is created.
The values that cannot be updated once the geofence is created are:
Get Geofence
This API gives you a filtered list of geofences. You can filter by geofence_id, created_at, start_date and end_date fields, user_id and group_id.
Sample Request
Using start_date and end_date
This filter allows you to filter the geofences within the given date range. These are non-mandatory fields and will be set to the current date by default.
You may also pass either the start_date or the end_date as filters. If you pass a specific start date, make sure it is less than the current date since the end date will be set default to the current date. If you pass a specific end_date and leave the start_date empty, make sure it is greater than the current date.
Below are the acceptable formats for the date filter:
Similar to the geofence_id, you can fetch the list of geofences that are tagged with the given user_id, which was initially used during the Create Geofence API. The user_id is created within the SDK during thecreateUser method and returns a unique user_id for identification within the Roam environment.
If you use theuser_id as a filter along with the date filter, the date filters will not be considered. And if you pass an empty or invalid user_id, the API will return an error.
Make sure the user_id used here belongs to the same project linked with the API key.
To fetch the list of geofences that are tagged with the given group_id, which was initially used during the Create Geofence API, you can pass the group_id in the header parameter.
You can get the group_id when you create a group using the Create Group API.
If you use group_id as a filter along with the date filter, the date filters will not be considered. Passing an empty or invalid group_id, will return an error.
Make sure the group_id used here belongs to the same project linked with the API key.
If the geofence flag is false for a user and location is not being published, then geofence events will not be processed for their location updates.
Events via Webhook
Roam supports the posting of events to webhooks in real-time. To enable posting events via webhook, first the webhook URL needs to be configured in the project using the dashboard (Project Settings -> integration) and should be enabled.
Events via API
Geofence events can be retrieved using the Roam API. The Get Events API lets you fetch entry or exit events of the users from your event-enabled geofences. The API also lets you filter by user, geofence, location, and more.
Delete Geofence
Delete any existing geofences from your projects by using the geofence_id.
You can delete the geofence with the delete API using the following two options:
Option 1: Delete geofence individually
You can delete one geofence at a time by passing the geofence ID as a query parameter.
Option 2: Delete geofences in bulk
By passing multiple geofence_ids as a body parameter, you can delete up to 200 geofences at a time.