Managing Flights

Submitting a Flight Plan

In order to create a flight on the AirMap platform, your application must first create a Flight Plan. Once a flight plan has been created and updated as desired, you may then submit the plan to create a flight:

## Submit Flight
curl -X "POST" "https://api.airmap.com/flight/v2/plan/{FLIGHT PLAN ID}/submit" \
     -H "Content-Type: application/json; charset=utf-8" \
     -H "Authorization: Bearer <AUTH_TOKEN>" \
     -H "X-API-Key: <API_KEY>" \
     -d $'{
  "public": true
}'

## The response includes the id of the created flight as well as details from the original flight plan:

{
  "status": "success",
  "data": {
    "aircraft_id": null,
    "flight_id": "flight|7ODwZZ5tawKovYclPOMyRhpY8nae",
    "start_time": "2017-10-11T03:28:07.375Z",
    "end_time": "2017-10-11T04:28:06.000Z",
    "buffer": 1,
    "max_altitude_agl": 60.96,
    "min_altitude_agl": 0,
    "target_altitude_agl": 0,
    "takeoff_latitude": 33.855057,
    "takeoff_longitude": -118.370991,
    "flight_features": {},
    "rulesets": [
      "usa_part_107"
    ],
    "id": "flight_plan|Q5R6JpxCB7wbxPha3KM6ahNlaWz0",
    "pilot_id": "auth0|591dea1006732e54be4b875f",
    "created_at": "2017-10-11T03:28:07.374Z",
    "deleted": false,
    "geometry": {
      "type": "Polygon",
      "coordinates": [
        [
          [
            -118.370990753174,
            33.8550565114206
          ],
          [
            -118.373050689697,
            33.8550297821458
          ],
          [
            -118.37347984314,
            33.8546733910155
          ],
          [
            -118.373061418533,
            33.8523122622167
          ],
          [
            -118.371934890747,
            33.851742017552
          ],
          [
            -118.369971513748,
            33.8517687478557
          ],
          [
            -118.369950056076,
            33.8528112231754
          ],
          [
            -118.370990753174,
            33.8550565114206
          ]
        ]
      ]
    }
  }
}
AirMap.submitFlightPlan(<#T##flightPlanId: String##String#>) { result in
    switch result {
    case .error(let error):
    // Handle error case
    case .value(let flightPlan):
        // Handle success case
    }
}
 AirMap.submitFlightPlan(flightPlanId, new AirMapCallback<AirMapFlightPlan>() {
    @Override
    protected void onSuccess(AirMapFlightPlan flightPlan) {
        AirMapLog.d(TAG, "Flight id: " + flightPlan.getFlightId());
    }

    @Override
    protected void onError(AirMapException e) {
        // Handle error case
    }
});

You are now ready to take flight with your aircraft!

Ending a Flight

After the aircraft has landed, your application should end the flight so the platform knows the aircraft is no longer flying:

curl -X "POST" "https://api.airmap.com/flight/v2/{FLIGHT ID}/end" \
	-H "Authorization: Bearer {YOUR ACCESS TOKEN}" \
	-H "X-API-Key: {YOUR API KEY}"
AirMap.endFlight(by: <#T##Flight Id#>) { result in
	switch result {
		case .error(let error):
    // Handle error case
  }
}
// only call end if the flight is active
AirMap.endFlight(flightId, new AirMapCallback<AirMapFlight>() {
    @Override
    public void onSuccess(AirMapFlight response) {
        // Handle success (remove from map, disable traffic alerts, etc)
    }

    @Override
    public void onError(AirMapException e) {
        // Handle error
    }
});
var request = require('superagent');

request  .post('https://api.airmap.com/flight/v2/{FLIGHT ID}/end')
  .set('Authorization', 'Bearer {YOUR ACCESS TOKEN}')
  .set('X-API-Key', '{YOUR API KEY}')
  .redirects(0)
  .end(function(err, res){
    if (err || !res.ok) {
      console.log('Oh no! error');
    } else {
      console.log('yay got ' + JSON.stringify(res.body));
    }
  });
import requests

def send_request():
    try:
        response = requests.post(
            url="https://api.airmap.com/flight/v2/{FLIGHT ID}/end",
            headers={
                "Authorization": "Bearer {YOUR ACCESS TOKEN}",
                "X-API-Key": "{YOUR API KEY}",
            },
        )
        print('Response HTTP Status Code: {status_code}'.format(
            status_code=response.status_code))
        print('Response HTTP Response Body: {content}'.format(
            content=response.content))
    except requests.exceptions.RequestException:
        print('HTTP Request failed')
require 'net/http'
require 'net/https'

def send_request
  begin
    uri = URI('https://api.airmap.com/flight/v2/{FLIGHT ID}/end')

    # Create client
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER

    # Create Request
    req =  Net::HTTP::Post.new(uri)
    # Add headers
    req.add_field "Authorization", "Bearer {YOUR ACCESS TOKEN}"
    # Add headers
    req.add_field "X-API-Key", "{YOUR API KEY}"

    # Fetch Request
    res = http.request(req)
    puts "Response HTTP Status Code: #{res.code}"
    puts "Response HTTP Response Body: #{res.body}"
  rescue StandardError => e
    puts "HTTP Request failed (#{e.message})"
  end
end

Viewing Flights

Your application can also request already created flights for reference. You have the option to retrieve a specific flight or retrieve a list of flights.

View Single Flight

To get a singe flight, provide the id of the flight to the Flight API:

curl -X "GET" "https://api.airmap.com/flight/v2/{FLIGHT ID}?enhance=true" \
	-H "X-API-Key: {YOUR API KEY}"

## The response details the specifics of the flight:

{
    "id": "c3ddceed-2617-43f3-b514-fd6e35815bf9",
    "pilot": {
        "id": "8cbaa552-9168-4f4a-aa0b-d028631e9cea",
        "username": "mattkoskela",
        "image": "https://cdn.airmap.com/images/users/uuid-asdf-asdf-sdf"
    },
    "aircraft": {
        "id": "fe80eccc-6db5-486e-96ca-dc3b71317d68",
        "make": "DJI",
        "model": "Phantom 3 Advanced",
        "image": "https://cdn.airmap.com/images/aircraft/dji-phantom-3-advanced.jpg",
    },
    "latitude": 34.016685,
    "longitude": 118.495092,
    "altitude": 220,
    "radius": 300,
    "start_time": "2016-05-18T00:28:17+00:00",
    "end_time": "2016-05-18T00:58:17+00:00",
}
AirMap.getFlight(by: <#T##Flight Id#>) { (result) in
      switch result {
      case .error(let error):
      // Handle error case
      case .value(let flight):
          // Handle success case
      }
  }
AirMap.getFlight(flightId, new AirMapCallback<AirMapFlight>() {
    @Override
    protected void onSuccess(AirMapFlight flight) {
        AirMapLog.d(TAG, "Flight : " + flight.getFlightId());
        
        // Handle success
    }

    @Override
    protected void onError(AirMapException e) {
        // Handle error
    }
});
var request = require('superagent');

request
  .get('https://api.airmap.com/flight/v2/{FLIGHT ID}')
  .set('X-API-Key', '{YOUR API KEY}')
  .query({"enhance":"true"})
  .redirects(0)
  .end(function(err, res){
    if (err || !res.ok) {
      console.log('Oh no! error');
    } else {
      console.log('yay got ' + JSON.stringify(res.body));
    }
  });
import requests

def send_request():
    try:
        response = requests.get(
            url="https://api.airmap.com/flight/v2/{FLIGHT ID}",
            params={
                "enhance": "true",
            },
            headers={
                "X-API-Key": "{YOUR API KEY}",
            },
        )
        print('Response HTTP Status Code: {status_code}'.format(
            status_code=response.status_code))
        print('Response HTTP Response Body: {content}'.format(
            content=response.content))
    except requests.exceptions.RequestException:
        print('HTTP Request failed')
require 'net/http'
require 'net/https'

def send_request
  begin
    uri = URI('https://api.airmap.com/flight/v2/{FLIGHT ID}?enhance=true')

    # Create client
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER


    # Create Request
    req =  Net::HTTP::Get.new(uri)
    # Add headers
    req.add_field "X-API-Key", "{YOUR API KEY}"

    # Fetch Request
    res = http.request(req)
    puts "Response HTTP Status Code: #{res.code}"
    puts "Response HTTP Response Body: #{res.body}"
  rescue StandardError => e
    puts "HTTP Request failed (#{e.message})"
  end
end


View List of Flights

You can also view a list of all of the authenticated pilot's flights by omitting the flight id in the endpoint:

curl -X "GET" "https://api.airmap.com/flight/v2/enhance=true" \
	-H "X-API-Key: {YOUR API KEY}"
AirMap.listPublicFlights { result in
    switch result {
      case .error(let error):
      // Handle error case
      case .value(let flights):
			// Handle success case
    }
}
AirMap.getPublicFlights(new AirMapCallback<List<AirMapFlight>>() {
    @Override
    protected void onSuccess(List<AirMapFlight> flights) {
        AirMapLog.d(TAG, "Public flights: " + flights);
        // Handle success
    }

    @Override
    protected void onError(AirMapException e) {
        // Handle error
    }
});
var request = require('superagent');

request
  .get('https://api.airmap.com/flight/v2/')
  .set('X-API-Key', '{YOUR API KEY}')
  .query({"enhance":"true"})
  .end(function(err, res){
    if (err || !res.ok) {
      console.log(err);
    } else {
      console.log(res.body);
    }
  });
import requests

def send_request():
    # GET Flight
    # GET https://api.airmap.io/flight/stage/

    try:
        response = requests.get(
            url="https://api.airmap.com/flight/v2/",
            params={
                "enhance": "true",
            },
            headers={
                "X-API-Key": "{YOUR API KEY}",
            },
        )
        print('Response HTTP Status Code: {status_code}'.format(
            status_code=response.status_code))
        print('Response HTTP Response Body: {content}'.format(
            content=response.content))
    except requests.exceptions.RequestException:
        print('HTTP Request failed')
require 'net/http'
require 'net/https'

def send_request
  # GET Flight (GET )

  begin
    uri = URI('https://api.airmap.com/flight/v2/?enhance=true')

    # Create client
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER


    # Create Request
    req =  Net::HTTP::Get.new(uri)
    # Add headers
    req.add_field "X-API-Key", "{YOUR API KEY}"

    # Fetch Request
    res = http.request(req)
    puts "Response HTTP Status Code: #{res.code}"
    puts "Response HTTP Response Body: #{res.body}"
  rescue StandardError => e
    puts "HTTP Request failed (#{e.message})"
  end
end

Finally, for HTTP requests, we can add a variety of query parameters that give us the flexibility to filter the results. (see Get Flights reference for full list). The mobile SDK's have convenience methods that accept an optional from (Date), to (Date) and limit (Int).

Pro Tip

Time parameters are typically in the standard ISO 8601 format 2018-01-01T12:00:00-08:00, but you can also use the string now to designate the current server time.

## Get Active Flight
## For example, to see all currently active flights, we can add in a `start_before` and `end_after` with the current time. 

curl "https://api.airmap.com/flight/v2/?pilot_id=auth0%7C591dea1006732e54be4b875f&end_after=now&start_before=now" \
     -H "Content-Type: application/json; charset=utf-8" \
     -H "Authorization: Bearer <AUTH_TOKEN>" \
     -H "X-API-Key: <API_KEY>" \
     -d $'{}'
 AirMap.listPublicFlights(from: <#T##Date?#>, to: <#T##Date?#>, limit: <#T##Int?#>) { result in
 
   switch result {
        case .error(let error):
        // Handle error case
        case .value(let flights):
        // Handle success case
   }        
}
AirMap.getPublicFlights(1000, fromDate, toDate, new AirMapCallback<List<AirMapFlight>>() {
    @Override
    protected void onSuccess(List<AirMapFlight> flights) {
        AirMapLog.d(TAG, "Public flights: " + flights);
        // Handle success
    }

    @Override
    protected void onError(AirMapException e) {
        // Handle error
    }
});

Deleting a Flight

Heads up!

You should only delete a flight if the current time is before the start time and the flight will not take place. Use the /end endpoint described above when landing a flight.

If desired, you may remove a flight from the pilot's history permanently:

curl -X "POST" "https://api.airmap.com/flight/v2/{FLIGHT ID}/delete" \
	-H "Authorization: Bearer {YOUR ACCESS TOKEN}" \
	-H "X-API-Key: {YOUR API KEY}"
AirMap.deleteFlight(<#T##flight: AirMapFlight##AirMapFlight#>) { result in
    switch result {
        case error(let error)
    }
}
AirMap.deleteFlight(flight, new AirMapCallback<Void>() {
    @Override
    protected void onSuccess(Void response) {
        // Handle success
    }

    @Override
    protected void onError(AirMapException e) {
        // Handle error
    }
});
var request = require('superagent');

request  .post('https://api.airmap.com/flight/v2/{FLIGHT ID}/delete')
  .set('Authorization', 'Bearer {YOUR ACCESS TOKEN}')
  .set('X-API-Key', '{YOUR API KEY}')
  .redirects(0)
  .end(function(err, res){
    if (err || !res.ok) {
      console.log('Oh no! error');
    } else {
      console.log('yay got ' + JSON.stringify(res.body));
    }
  });
import requests

def send_request():
    try:
        response = requests.post(
            url="https://api.airmap.com/flight/v2/{FLIGHT ID}/delete",
            headers={
                "Authorization": "Bearer {YOUR ACCESS TOKEN}",
                "X-API-Key": "{YOUR API KEY}",
            },
        )
        print('Response HTTP Status Code: {status_code}'.format(
            status_code=response.status_code))
        print('Response HTTP Response Body: {content}'.format(
            content=response.content))
    except requests.exceptions.RequestException:
        print('HTTP Request failed')
require 'net/http'
require 'net/https'

def send_request
  begin
    uri = URI('https://api.airmap.com/flight/v2/{FLIGHT ID}/delete')

    # Create client
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER

    # Create Request
    req =  Net::HTTP::Post.new(uri)
    # Add headers
    req.add_field "Authorization", "Bearer {YOUR ACCESS TOKEN}"
    # Add headers
    req.add_field "X-API-Key", "{YOUR API KEY}"

    # Fetch Request
    res = http.request(req)
    puts "Response HTTP Status Code: #{res.code}"
    puts "Response HTTP Response Body: #{res.body}"
  rescue StandardError => e
    puts "HTTP Request failed (#{e.message})"
  end
end

What's Next

Learn how to interact with the airspace in realtime with Traffic Alerts and Telemetry

Traffic Alerts
Sending Telemetry

Managing Flights