Authentication
Before accessing the APIs, Spire must provide users with an API token for the Aviation APIs.
API endpoints#
All our products can be accessed through these API endpoints:
- Tracking Stream
- Tracking History
https://api.airsafe.spire.com/v2/targets/stream
https://api.airsafe.spire.com/v2/targets/history
Authentication header#
All queries addressed to our API are using Bearer Authentication.
- Bash
- Python
- Javascript
- Golang
- Java
curl -H "Authorization: Bearer <your_token>" "https://api.airsafe.spire.com/v2/<product_endpoint>"
import sys
import requests
try:
response = requests.get(
"https://api.airsafe.spire.com/v2/<product_endpoint>",
headers={"Authorization": f"Bearer <your_token>"},
)
except Exception as e:
print("An error happened")
sys.exit()
print(response)
fetch(`https://api.airsafe.spire.com/v2/<product_endpoint>`, {
headers: {
Authorization: `Bearer <your_token>`,
},
}).then((response) => {
console.log(response);
});
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
)
func main() {
req, err := http.NewRequest("GET", "https://api.airsafe.spire.com/v2/<product_endpoint>", nil)
if err != nil {
log.Fatal("Error reading request. ", err)
}
req.Header.Set("Authorization", "Bearer <your_token>")
client := &http.Client{Timeout: time.Second * 10}
resp, err := client.Do(req)
if err != nil {
log.Fatal("Error reading response. ", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal("Error reading body. ", err)
}
fmt.Printf("%s\n", body)
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.ExecutionException;
class Main {
public static void main(String[] args) throws IOException, InterruptedException, ExecutionException {
URL url = new URL("https://api.airsafe.spire.com/v2/<product_endpoint>");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Authorization", "Bearer <your_token>");
try(BufferedReader responseLine = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
responseLine.lines().forEach(System.out::println);
}
}
}