Step 1: Get list of all trips
Firstly, you need to get the list of all trips with the below API. You need to use your project API key to authenticate the API.
To get the trips list based on user_id:
curl --location --request GET 'https://api.roam.ai/v1/api/trips/?user_id=5f7d95f1ffb3fb58435309de' \
--header 'Api-key: 4db3d709296a4a518a03bf15f37c55b7' \
--header 'Content-Type: application/json'
To get the trips list between dates:
curl --location --request GET 'https://api.roam.ai/v1/api/trips/?start_date=2022-01-01&end_date=2020-01-31 \
--header 'Api-key: 4db3d709296a4a518a03bf15f37c55b7' \
--header 'Content-Type: application/json'
Sample Response
{
"status": true,
"msg": "Success.",
"code": 200,
"data": [
{
"id": "5f7d9926e5fc233610297c76",
"project_id": "5f7d656ae5fc233611297c6c",
"origins": [
{
"id": "5f7d9926e5fc233610297c77",
"trip_id": "5f7d9926e5fc233610297c76",
"created_at": "2021-06-07T10:32:06.527",
"updated_at": "2021-06-07T10:32:06.538",
"coordinates": {
"type": "Point",
"coordinates": [
77.622977,
12.917042
]
},
"loc_type": "origin"
},
{
"id": "5f7d9926e5fc233610297c78",
"trip_id": "5f7d9926e5fc233610297c76",
"created_at": "2021-06-07T10:32:06.545",
"updated_at": "2021-06-07T10:32:06.552",
"coordinates": {
"type": "Point",
"coordinates": [
77.650239,
12.924304
]
},
"loc_type": "origin"
},
{
"id": "5f7d9926e5fc233610297c79",
"trip_id": "5f7d9926e5fc233610297c76",
"created_at": "2021-06-07T10:32:06.560",
"updated_at": "2021-06-07T10:32:06.571",
"coordinates": {
"type": "Point",
"coordinates": [
77.743206,
12.954302
]
},
"loc_type": "origin"
}
],
"destinations": [
{
"id": "5f7d9926e5fc233610297c7a",
"trip_id": "5f7d9926e5fc233610297c76",
"created_at": "2021-06-07T10:32:06.578",
"updated_at": "2021-06-07T10:32:06.584",
"coordinates": {
"type": "Point",
"coordinates": [
78.743206,
12.954302
]
},
"loc_type": "destination"
}
],
"events": [
{
"id": "5f7d99298fd7a058fbff9ff9",
"trip_id": "5f7d9926e5fc233610297c76",
"user_id": "5f7d95f1ffb3fb58435309de",
"event_type": "geospark:trip:created",
"created_at": "2021-06-07T10:32:09.699",
"is_deleted": false,
"event_source": "geospark:trip",
"event_version": "1.0"
}
],
"user_id": "5f7d95f1ffb3fb58435309de",
"is_started": false,
"is_ended": false,
"is_deleted": false,
"created_at": "2021-06-07T10:32:06.522",
"updated_at": "2021-06-07T10:32:06.603"
}
]
}
Once you get the list of trip id’s as per your filters, you can proceed to the next step.
Step 2: Get location count
Now you can use the trip_id one by one from the previous step to trip summary api, which will give the trip route.
curl --location --request GET 'https://api.roam.ai/v1/api/trips/summary/?trip_id=60bdiuy006f8a03affc5968a' \
--header 'Api-key: 63598c5b3aa84f14914013700402bbc6'
Response
{
"status": true,
"msg": "Success.",
"code": 200,
"data": {
"trip_id": "60bdebd006f8a03affc5968a",
"user_id": "60bdebb051efb059ab7daf67",
"project_id": "60af306a8ce7db2392eb7a75",
"trip_status": "completed",
"distance_covered": 129.25,
"duration": 791,
"route_indexes": [ ],
"route": [
{
"coordinates": {
"type": "Point",
"coordinates": [
85.06944606259113,
25.605387669529264
]
},
"altitude": 55.26,
"activity": "STOP",
"recorded_at": "2021-06-07T09:50:53.344",
"duration": 0,
"elevation_gain": 0
},
{
"coordinates": {
"type": "Point",
"coordinates": [
85.06933924413998,
25.60538919064786
]
},
"altitude": 55.41,
"activity": "MOVING",
"recorded_at": "2021-06-07T09:51:17.232",
"distance": 10.71,
"duration": 23,
"elevation_gain": 0
},
{
"coordinates": {
"type": "Point",
"coordinates": [
85.06922514582031,
25.60543086974654
]
},
"altitude": 55.17,
"activity": "MOVING",
"recorded_at": "2021-06-07T09:51:46.472",
"distance": 23.05,
"duration": 53,
"elevation_gain": 0
}
],
"total_elevation_gain": 0
}
}
The count of route array from the response is the total location count for the trip. You can run this in a loop for all the trip ids to get the location count for all the trips.
If you need any additional help, feel free to checkout our discord community, or send us an email at support@roam.ai