All Felt API endpoints are hosted at the following base URL:
https://felt.com/api/v2
Create an API token
All calls to the Felt API must be authenticated. The easiest way to authenticate your API calls is by creating a API token and providing it as a Bearer token in the request header.
The easiest way to interact with the Felt API is by using our felt-python SDK. You can install it with the following command:
pipinstallfelt-python
Example: Creating a new map
Creating a new map is as simple as making a POST request to the maps endpoint.
# Your API token should look like this:# FELT_API_TOKEN="felt_pat_ABCDEFUDQPAGGNBmX40YNhkCRvvLI3f8/BCwD/g8"FELT_API_TOKEN="<YOUR_API_TOKEN>"curl-L \-XPOST \-H"Content-Type: application/json" \-H"Authorization: Bearer ${FELT_API_TOKEN}" \"https://felt.com/api/v2/maps" \-d'{"title": "My newly created map"}'
import requests# This looks like:# api_token = "felt_pat_ABCDEFUDQPAGGNBmX40YNhkCRvvLI3f8/BCwD/g8"api_token ="<YOUR_API_TOKEN>"r = requests.post("http://felt.com/api/v2/maps", json={"title": "My newly created map"}, headers={"Authorization": f"Bearer {api_token}"})assert r.okmap_id = r.json()["id"]print(r.json())
import osfrom felt_python import create_map# Setting your API token as an env variable can save# you from repeating it in every function callos.environ["FELT_API_TOKEN"]="<YOUR_API_TOKEN>"response =create_map( title="My newly created map", lat=40, lon=-3, public_access="private",)map_id = response["id"]
Notice in the response the "id" property. Every map has a unique ID, which is also a part of the map's URL. Let's take note of it for future API calls.
Also part of the response is a "url" property, which is the URL to your newly-created map. Feel free to open it! For now, it should just show a blank map.
Example: Uploading a layer from a URL
Now that we've created a new map, let's add some data to it. We'll need the map_id included in the previous call's response.
# Store the map ID from the previous call:# MAP_ID="CjU1CMJPTAGofjOK3ICf1D"MAP_ID="<YOUR_MAP_ID>"curl-L \-XPOST \-H"Content-Type: application/json" \-H"Authorization: Bearer ${FELT_API_TOKEN}" \"https://felt.com/api/v2/maps/${MAP_ID}/upload" \ -d '{"import_url":"https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson", "name": "USGS Earthquakes"}'
Like maps, layers also have unique identifiers. Let's take note of this one (also called "id" in the response) so we can style it in the next call.
You can see the uploaded result in your map:
Example: Styling a layer
Layer styles are defined in the Felt Style Language, a JSON-based specification that allows customizing a layer's style, legend, label and popups.
Layers can be styled at upload time or afterwards. Let's change the style of our newly-created earthquakes layer so that points are bigger and in green color:
# Store the layer ID from the previous call:# LAYER_ID="CjU1CMJPTAGofjOK3ICf1D"LAYER_ID="<YOUR_LAYER_ID>"curl-L \-XPOST \"https://felt.com/api/v2/maps/${MAP_ID}/layers/${LAYER_ID}/update_style" \-H"Content-Type: application/json" \-H"Authorization: Bearer ${FELT_API_TOKEN}" \ --data '{"style": {"paint": {"color": "green", "opacity": 0.9, "size": 30, "strokeColor": "auto", "strokeWidth": 1}, "legend": {}, "type": "simple", "version": "2.1"}}'