Skip to main content

Create Geo Location

Enterprise Only
This API is available exclusively in Countly Enterprise.

Endpoint

/i/geolocations/create

Overview

Creates a geolocation entry with a center point and radius.

Authentication

  • Authentication methods:
    • API Key (parameter): api_key=YOUR_API_KEY
    • Auth Token (parameter): auth_token=YOUR_AUTH_TOKEN
    • Auth Token (header): countly-token: YOUR_AUTH_TOKEN

Permissions

  • Required permission: Create on the geo feature
  • Additional rule: creating a global (non-app-specific) location is allowed only for global admins

Request Parameters

ParameterTypeRequiredDescription
api_keyStringYes (or auth_token)API key authentication
auth_tokenStringYes (or api_key)Auth token authentication
app_idStringYesApplication context for permission validation
argsObject (JSON string)YesStringified location object

args Object Fields

FieldTypeRequiredDescription
titleStringYesLocation title
radiusNumberYesRadius around the center point
unitStringYesUnit label stored with the location
geoObjectYesGeoJSON-like point object
geo.typeStringYesMust be Point
geo.coordinatesArrayYes[longitude, latitude]
appStringNoApp ID to make the location app-specific

Response

Success Response

{
"_id": "62616692a9ddc55457bad406",
"title": "Berlin Store",
"radius": 5,
"unit": "km",
"geo": {
"type": "Point",
"coordinates": [13.405, 52.52]
},
"app": "609bd78d90d7a416d4dfb984",
"created": "2022-04-21T14:13:38.174Z",
"address": "Berlin, Germany"
}

Response Fields

FieldTypeDescription
_idStringGeolocation ID
titleStringLocation title
radiusNumberStored radius value
unitStringStored unit label
geoObjectLocation point (type, coordinates)
appStringApp ID for app-specific locations (omitted for global locations)
createdStringCreation timestamp
addressStringReverse-geocoded address if available

Error Responses

HTTP StatusResponse
200{"error":"Not enough args"}
200{"error":"Bad location geo object"}
200{"error":"Only global admin is allowed to create non-app-specific geolocations"}
200{"error":"Couldn't find the app"}
200{"error":"Not an admin of the app"}
200{"error":"Server db Error"}
400Validation error from auth/permission layer (for example missing required request params)

Behavior/Processing

  1. Parses args from a JSON string.
  2. Validates required fields and point structure (geo.type, geo.coordinates).
  3. Resolves app authorization rules.
  4. Reverse-geocodes coordinates into address.
  5. Inserts document into countly.geos.
  6. Returns the created location document.

Database Collections

CollectionUsed forData touched by this endpoint
countly.geosEndpoint data source** - Stores geolocation documents
countly.appsEndpoint data source** - App lookup and admin permission checks

Examples

Example 1: Create App-Specific Location

Endpoint form:

https://your-server.com/i/geolocations/create?api_key=YOUR_API_KEY&app_id=609bd78d90d7a416d4dfb984&args={"title":"Berlin Store","radius":5,"unit":"km","geo":{"type":"Point","coordinates":[13.405,52.52]},"app":"609bd78d90d7a416d4dfb984"}

Decoded args object:

{
"title": "Berlin Store",
"radius": 5,
"unit": "km",
"geo": {
"type": "Point",
"coordinates": [13.405, 52.52]
},
"app": "609bd78d90d7a416d4dfb984"
}

Example 2: Create Global Location (Global Admin Only)

Endpoint form:

https://your-server.com/i/geolocations/create?api_key=YOUR_GLOBAL_ADMIN_API_KEY&app_id=609bd78d90d7a416d4dfb984&args={"title":"Global HQ Radius","radius":3,"unit":"km","geo":{"type":"Point","coordinates":[-0.1276,51.5072]}}

Decoded args object:

{
"title": "Global HQ Radius",
"radius": 3,
"unit": "km",
"geo": {
"type": "Point",
"coordinates": [-0.1276, 51.5072]
}
}

Limitations

  • geo.type must be Point.
  • geo.coordinates must contain exactly two values: [longitude, latitude].
  • unit is stored as metadata; geo filtering logic uses radius as kilometer-based spherical distance.

Ⓔ Enterprise

This feature is part of Countly Enterprise.

Get Access:

Already a Customer? Use support portal if you have any questions


Last Updated

2026-02-16