# Add Flight Log

This API provides programmatic access for adding flight log entries with secure API key authentication. It records essential telemetry data and other relevant information, creating a comprehensive record of drone operations.

### Authentication&#x20;

To use the API, insert your API key in the Authorization header like this:

```javascript
Authorization: Bearer <YOUR_API_KEY>
```

Replace `<YOUR_API_KEY>` with your AeroGCS API key. Without it, you'll get a 401 Unauthorized error.

### Method

**POST**&#x20;

#### Post Data Parameters

| Parameter       | Description                                                | Optional | Example                              |
| --------------- | ---------------------------------------------------------- | -------- | ------------------------------------ |
| **droneID**     | Unique identifier for the drone.                           | No       | P00001004F002B3131510137383337       |
| **teleData**    | Telemetry data collected during the flight.                | No       | See example JSON object below        |
| **flightID**    | Unique identifier for the flight.                          | No       | ebddac29-c44d-481e-90ff-48a344080fa8 |
| **key**         | Key indicating the type of telemetry data.                 | No       | AS\_TELE\_DATA                       |
| **aerostackID** | Unique identifier for the Aerostack system.                | No       | 999e8416-d5af-4828-8c44-a83f1e556d4e |
| **timestamp**   | Timestamp indicating when the telemetry data was received. | No       | 1715083563                           |

Example of the `teleData` object:

```json
{
    "alt": 1.37,
    "bat": "43.631",
    "dir": "18.00",
    "flowRate": "0.00",
    "lat": 28.9852907,
    "liquidConsumed": "00",
    "liveObstacleDistance": "2.5",
    "lon": 78.0017839,
    "mod": "16",
    "pit": -1.6977644338993196,
    "rol": 0.7457296585355124,
    "sat": 28,
    "sprayPumpRate": "41",
    "sprayedArea": "0.0000",
    "sprayedDistance": "1283.448",
    "vel": 0.05128028988838196,
    "yaw": 18.24909237728412
}
```

### HTTP Request <a href="#http-request-33" id="http-request-33"></a>

{% code overflow="wrap" %}

```url
https://ags.aeromegh.com/Aeromegh/addFlightLog
```

{% endcode %}

### HTTP Response <a href="#http-response-32" id="http-response-32"></a>

Response Codes Explanation:

| Code | Details                     | Message                      |
| ---- | --------------------------- | ---------------------------- |
| 200  | The request was successful. | "OK"                         |
| 400  | Request parameters missing. | "Request parameters missing" |
| 500  | Internal server error.      | "Internal server error"      |

### Code Snippet

Examples of how you can call this API using curl, Node.js, and Python:

{% tabs %}
{% tab title="curl" %}

```json
curl --location 'https://ags.aeromegh.com/Aeromegh/addFlightLog' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API_KEY>' \
--data '{
    "droneID": "P00001004F002B3131510137383337",
    "teleData": {"alt":1.37,"bat":"43.631","dir":"18.00","flowRate":"0.00","lat":28.9852907,"liquidConsumed":"00","liveObstacleDistance":"2.5","lon":78.0017839,"mod":"16","pit":-1.6977644338993196,"rol":0.7457296585355124,"sat":28,"sprayPumpRate":"41","sprayedArea":"0.0000","sprayedDistance":"1283.448","vel":0.05128028988838196,"yaw":18.24909237728412},
    "flightID": "ebddac29-c44d-481e-90ff-48a344080fa8",
    "key": "AS_TELE_DATA",
    "aerostackID":"999e8416-d5af-4828-8c44-a83f1e556d4e",
    "timestamp":"1715083563"
}

'
```

{% endtab %}

{% tab title="Node" %}

```javascript
//Please install 'axios' module first
//Set your API key before making the request
const axios = require('axios');
let data = JSON.stringify({
  "droneID": "P00001004F002B3131510137383337",
  "teleData": {
    "alt": 1.37,
    "bat": "43.631",
    "dir": "18.00",
    "flowRate": "0.00",
    "lat": 28.9852907,
    "liquidConsumed": "00",
    "liveObstacleDistance": "2.5",
    "lon": 78.0017839,
    "mod": "16",
    "pit": -1.6977644338993196,
    "rol": 0.7457296585355124,
    "sat": 28,
    "sprayPumpRate": "41",
    "sprayedArea": "0.0000",
    "sprayedDistance": "1283.448",
    "vel": 0.05128028988838196,
    "yaw": 18.24909237728412
  },
  "flightID": "ebddac29-c44d-481e-90ff-48a344080fa8",
  "key": "AS_TELE_DATA",
  "aerostackID": "999e8416-d5af-4828-8c44-a83f1e556d4e",
  "timestamp": "1715083563"
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://ags.aeromegh.com/Aeromegh/addFlightLog',
  headers: { 
    'Content-Type': 'application/json', 
    'Authorization': 'Bearer <API_KEY>'
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

```

{% endtab %}

{% tab title="Python" %}

```python
//Please install 'requests' AND 'json' package first
//Set your API key before making the request
import requests
import json

url = "https://ags.aeromegh.com/Aeromegh/addFlightLog"

payload = json.dumps({
  "droneID": "P00001004F002B3131510137383337",
  "teleData": {
    "alt": 1.37,
    "bat": "43.631",
    "dir": "18.00",
    "flowRate": "0.00",
    "lat": 28.9852907,
    "liquidConsumed": "00",
    "liveObstacleDistance": "2.5",
    "lon": 78.0017839,
    "mod": "16",
    "pit": -1.6977644338993196,
    "rol": 0.7457296585355124,
    "sat": 28,
    "sprayPumpRate": "41",
    "sprayedArea": "0.0000",
    "sprayedDistance": "1283.448",
    "vel": 0.05128028988838196,
    "yaw": 18.24909237728412
  },
  "flightID": "ebddac29-c44d-481e-90ff-48a344080fa8",
  "key": "AS_TELE_DATA",
  "aerostackID": "999e8416-d5af-4828-8c44-a83f1e556d4e",
  "timestamp": "1715083563"
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer <API_KEY>'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Note:** Replace **`<API_KEY>`** with the actual API\_KEY provided by Aeromegh.
{% endhint %}

### &#x20;API Response

Example of API response in JSON format:

```json
{
    "message": "Flight log added"
}
```

### API Response Parameter&#x20;

The API response contains the following parameters:

| Parameter   | Description                                                                                                                                                                               |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **message** | A message indicating the result of the operation. In this case, it confirms that the flight log has been successfully added to the Aeromegh system. The value will be "Flight log added". |
