The Location API is available from version v0.5.
Version v0.5 is read-only. It allows you to list locations and get location details.
Version v0.6 adds the ability to create and update locations.
List Locations
URL: GET https://www.commcarehq.org/a/[domain]/api/[version]/location/
Locations can be created using a POST to list the endpoint (as per the link above).Locations can be filtered by the following attributes as request parameters:
...
{
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 2
},
"objects": [
{
"created_at": "2023-05-09T16:10:47.225938",
"domain": "[domain]",
"external_id": null,
"id": 1,
"last_modified": "2023-05-09T16:10:47.225947",
"latitude": null,
"location_data": {},
"location_id": "f373a6837c1243938abfc56618cce88b",
"location_type": "https://www.commcarehq.org/a/[domain]/api/v0.5/location_type/1/",
"longitude": null,
"name": "Namibia",
"parent": null,
"resource_uri": "https://www.commcarehq.org/a/[domain]/api/v0.5/location/f373a6837c1243938abfc56618cce88b/",
"site_code": "namibia"
},
...
]
}
Location Details
URL: GET https://www.commcarehq.org/a/[domain]/api/[version]/location/[location_id]
The Location API is read-only. Following v0.6, both GET and PUT is supported. For applications using v0.5, only GET is supported.
Updating the location is done via a PUT to a “detail” endpoint.
Sample output:
{
"created_at": "2023-05-09T16:10:47.225938",
"domain": "[domain]",
"external_id": null,
"id": 1,
"last_modified": "2023-05-09T16:10:47.225947",
"latitude": null,
"location_data": {},
"location_id": "f373a6837c1243938abfc56618cce88b",
"location_type": "https://www.commcarehq.org/a/[domain]/api/v0.5/location_type/1/",
"longitude": null,
"name": "Namibia",
"parent": null,
"resource_uri": "https://www.commcarehq.org/a/[domain]/api/v0.5/location/f373a6837c1243938abfc56618cce88b/",
"site_code": "namibia"
}
Create Location
POST https://www.commcarehq.org/a/[domain]/api/[version]/location/
Available from version v0.6.
Update Location
PUT https://www.commcarehq.org/a/[domain]/api/[version]/location/[location_id]
Available from version v0.6.
List Location Types
URL: GET https://www.commcarehq.org/a/[domain]/api/[version]/location_type/
Sample output:
{
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 1
},
"objects": [
{
"administrative": true,
"code": "country",
"domain": "[domain]",
"id": 1,
"name": "Country",
"parent": null,
"resource_uri": "https://www.commcarehq.org/a/[domain]/api/v0.5/location_type/1/",
"shares_cases": false,
"view_descendants": false
}
]
}
Location Type Details
URL: GET https://www.commcarehq.org/a/[domain]/api/[version]/location_type/[id]The Location API is read-only. Only the GET request method is supported.
Sample output:
{
"administrative": true,
"code": "country",
"domain": "[domain]",
"id": 1,
"name": "Country",
"parent": null,
"resource_uri": "https://www.commcarehq.org/a/[domain]/api/v0.5/location_type/1/",
"shares_cases": false,
"view_descendants": false
}