# Trips

> Documentation index: https://ridewithgps.com/api/v1/doc/llms.txt

A trip is a recorded ride. Upload a GPX, TCX, KML or FIT file to create trips: the upload runs in the background and returns a [task](https://ridewithgps.com/api/v1/doc/endpoints/tasks.md).

See also: [Routes and trips](https://ridewithgps.com/api/v1/doc/reference/routes_and_trips.md), [Track points](https://ridewithgps.com/api/v1/doc/reference/track_points.md), [Activity types](https://ridewithgps.com/api/v1/doc/reference/activity_types.md).

OpenAPI specification for these endpoints: https://ridewithgps.com/api/v1/openapi/openapi_trips.yaml

## Returns a list of trips

`GET /api/v1/trips.json`

Returns a paginated list of trips for the authenticated user.

Supports filtering by `name`, `visibility`, `distance_min`, `distance_max`, `elevation_gain_min`, `elevation_gain_max` and `stationary`.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `x-rwgps-api-key` | string | yes | API key for identifying the client application |
| `x-rwgps-auth-token` | string | yes | Authentication token for the user |

### Parameters

| Name | Type | In | Required | Description |
| --- | --- | --- | --- | --- |
| `page` | integer | query | no | Page number for pagination |
| `page_size` | integer | query | no | Number of items per page (20-200) |
| `name` | string | query | no | Filter by name (partial match) |
| `visibility` | string | query | no | Filter by visibility. One of: `public`, `followers_only`, `mutual_followers_only`, `private`. |
| `distance_min` | integer | query | no | Minimum distance in meters |
| `distance_max` | integer | query | no | Maximum distance in meters |
| `elevation_gain_min` | integer | query | no | Minimum elevation gain in meters |
| `elevation_gain_max` | integer | query | no | Maximum elevation gain in meters |
| `stationary` | string | query | no | Filter by stationary status. One of: `true`, `false`. |

### Response `200`

| Name | Type | Description |
| --- | --- | --- |
| `trips` | array of objects |  |
| `trips[].id` | integer |  |
| `trips[].user_id` | integer |  |
| `trips[].url` | string |  |
| `trips[].html_url` | string |  |
| `trips[].visibility` | string |  |
| `trips[].name` | string |  |
| `trips[].description` | string or null |  |
| `trips[].departed_at` | date-time or null |  |
| `trips[].time_zone` | string or null |  |
| `trips[].locality` | string or null |  |
| `trips[].administrative_area` | string or null |  |
| `trips[].country_code` | string or null |  |
| `trips[].activity_type` | string or null |  |
| `trips[].fit_sport` | integer or null |  |
| `trips[].fit_sub_sport` | integer or null |  |
| `trips[].stationary` | boolean |  |
| `trips[].distance` | number | Distance in meters |
| `trips[].duration` | number | Duration in seconds |
| `trips[].moving_time` | number | Moving time in seconds |
| `trips[].elevation_gain` | number | Elevation gain in meters |
| `trips[].elevation_loss` | number | Elevation loss in meters |
| `trips[].first_lat` | number or null |  |
| `trips[].first_lng` | number or null |  |
| `trips[].last_lat` | number or null |  |
| `trips[].last_lng` | number or null |  |
| `trips[].sw_lat` | number or null |  |
| `trips[].sw_lng` | number or null |  |
| `trips[].ne_lat` | number or null |  |
| `trips[].ne_lng` | number or null |  |
| `trips[].track_type` | string or null |  |
| `trips[].terrain` | string or null |  |
| `trips[].difficulty` | string or null |  |
| `trips[].avg_speed` | number or null | Average speed in kilometers per hour |
| `trips[].max_speed` | number or null | Maximum speed in kilometers per hour |
| `trips[].avg_cad` | number or null | Average cadence in rounds per minute |
| `trips[].min_cad` | number or null | Minimum cadence in rounds per minute |
| `trips[].max_cad` | number or null | Maximum cadence in rounds per minute |
| `trips[].avg_hr` | number or null | Average heart rate in beats per minute |
| `trips[].min_hr` | number or null | Minimum heart rate in beats per minute |
| `trips[].max_hr` | number or null | Maximum heart rate in beats per minute |
| `trips[].avg_watts` | number or null | Average power in watts |
| `trips[].min_watts` | number or null | Minimum power in watts |
| `trips[].max_watts` | number or null | Maximum power in watts |
| `trips[].calories` | number or null | Calories burned |
| `trips[].device` | string or null |  |
| `trips[].created_at` | date-time |  |
| `trips[].updated_at` | date-time |  |
| `meta` | object |  |
| `meta.pagination` | object |  |
| `meta.pagination.record_count` | integer | Total number of records |
| `meta.pagination.page_count` | integer | Total number of pages |
| `meta.pagination.page_size` | integer | Number of records per page |
| `meta.pagination.next_page_url` | string or null | URL for the next page (null if last page) |

### Errors

- `401` Unauthorized

### Example request

```bash
curl \
  -H "x-rwgps-api-key: $API_KEY" \
  -H "x-rwgps-auth-token: $AUTH_TOKEN" \
  https://ridewithgps.com/api/v1/trips.json
```

### Example response

```json
{
  "trips": [
    {
      "id": 123,
      "user_id": 123,
      "url": "https://ridewithgps.com/api/v1/trips/123.json",
      "html_url": "https://ridewithgps.com/trips/123",
      "visibility": "public",
      "name": "Forest Park loop",
      "description": "Morning ride through Forest Park",
      "departed_at": "2000-01-01T08:00:00-08:00",
      "time_zone": "America/Los_Angeles",
      "locality": "Portland",
      "administrative_area": "OR",
      "country_code": "US",
      "activity_type": "cycling:road",
      "fit_sport": 2,
      "fit_sub_sport": 7,
      "stationary": false,
      "distance": 40237,
      "duration": 7856,
      "moving_time": 7204,
      "elevation_gain": 457,
      "elevation_loss": 461,
      "first_lat": 45.521529,
      "first_lng": -122.691804,
      "last_lat": 45.521529,
      "last_lng": -122.691804,
      "sw_lat": 45.432536,
      "sw_lng": -122.836749,
      "ne_lat": 45.652881,
      "ne_lng": -122.471777,
      "track_type": "loop",
      "terrain": "rolling",
      "difficulty": "moderate",
      "avg_speed": 20.1,
      "max_speed": 52.3,
      "avg_cad": 87,
      "min_cad": 0,
      "max_cad": 119,
      "avg_hr": 143,
      "min_hr": 87,
      "max_hr": 177,
      "avg_watts": 183,
      "min_watts": 0,
      "max_watts": 627,
      "calories": 1318,
      "device": "Garmin Edge 840",
      "created_at": "2000-01-01T12:00:00Z",
      "updated_at": "2000-01-01T12:00:00Z"
    }
  ],
  "meta": {
    "pagination": {
      "record_count": 45,
      "page_count": 3,
      "page_size": 20,
      "next_page_url": "https://ridewithgps.com/api/v1/trips.json?page=2"
    }
  }
}
```

## Returns the specified trip

`GET /api/v1/trips/{id}.json`

Returns detailed information about a specific trip

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `x-rwgps-api-key` | string | yes | API key for identifying the client application |
| `x-rwgps-auth-token` | string | yes | Authentication token for the user |

### Parameters

| Name | Type | In | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | integer | path | yes | Trip ID |
| `privacy_code` | string | query | no | Privacy code for the non public asset |

### Response `200`

| Name | Type | Description |
| --- | --- | --- |
| `trip` | object |  |
| `trip.id` | integer |  |
| `trip.user_id` | integer |  |
| `trip.url` | string |  |
| `trip.html_url` | string |  |
| `trip.visibility` | string |  |
| `trip.name` | string |  |
| `trip.description` | string or null |  |
| `trip.departed_at` | date-time or null |  |
| `trip.time_zone` | string or null |  |
| `trip.locality` | string or null |  |
| `trip.administrative_area` | string or null |  |
| `trip.country_code` | string or null |  |
| `trip.activity_type` | string or null |  |
| `trip.fit_sport` | integer or null |  |
| `trip.fit_sub_sport` | integer or null |  |
| `trip.stationary` | boolean |  |
| `trip.distance` | number | Distance in meters |
| `trip.duration` | number | Duration in seconds |
| `trip.moving_time` | number | Moving time in seconds |
| `trip.elevation_gain` | number | Elevation gain in meters |
| `trip.elevation_loss` | number | Elevation loss in meters |
| `trip.first_lat` | number or null |  |
| `trip.first_lng` | number or null |  |
| `trip.last_lat` | number or null |  |
| `trip.last_lng` | number or null |  |
| `trip.sw_lat` | number or null |  |
| `trip.sw_lng` | number or null |  |
| `trip.ne_lat` | number or null |  |
| `trip.ne_lng` | number or null |  |
| `trip.track_type` | string or null |  |
| `trip.terrain` | string or null |  |
| `trip.difficulty` | string or null |  |
| `trip.avg_speed` | number or null | Average speed in kilometers per hour |
| `trip.max_speed` | number or null | Maximum speed in kilometers per hour |
| `trip.avg_cad` | number or null | Average cadence in rounds per minute |
| `trip.min_cad` | number or null | Minimum cadence in rounds per minute |
| `trip.max_cad` | number or null | Maximum cadence in rounds per minute |
| `trip.avg_hr` | number or null | Average heart rate in beats per minute |
| `trip.min_hr` | number or null | Minimum heart rate in beats per minute |
| `trip.max_hr` | number or null | Maximum heart rate in beats per minute |
| `trip.avg_watts` | number or null | Average power in watts |
| `trip.min_watts` | number or null | Minimum power in watts |
| `trip.max_watts` | number or null | Maximum power in watts |
| `trip.calories` | number or null | Calories burned |
| `trip.device` | string or null |  |
| `trip.created_at` | date-time |  |
| `trip.updated_at` | date-time |  |
| `trip.track_points` | array of objects |  |
| `trip.track_points[].x` | number | Longitude |
| `trip.track_points[].y` | number | Latitude |
| `trip.track_points[].d` | number | Distance from start in meters |
| `trip.track_points[].e` | integer | Elevation in meters |
| `trip.track_points[].t` | integer | Unix epoch time in seconds |
| `trip.track_points[].s` | number | Speed in kilometers per hour |
| `trip.track_points[].T` | integer | Temperature in degrees celsius |
| `trip.track_points[].h` | integer | Heart rate in beats per minute |
| `trip.track_points[].c` | integer | Cadence in rounds per minute |
| `trip.track_points[].p` | integer | Power output in watts |
| `trip.track_points[].pb` | integer | Power balance percent L/R |
| `trip.track_points[].lap` | boolean | Start of lap |
| `trip.track_points[].k` | boolean | Exclude from metrics |
| `trip.track_points[].m` | boolean | User modified |
| `trip.gear` | object |  |
| `trip.gear.id` | integer |  |
| `trip.gear.make` | string or null |  |
| `trip.gear.model` | string or null |  |
| `trip.gear.description` | string or null |  |
| `trip.gear.exclude_from_totals` | boolean |  |
| `trip.gear.created_at` | date-time |  |
| `trip.photos` | array of objects |  |
| `trip.photos[].id` | integer |  |
| `trip.photos[].url` | string |  |
| `trip.photos[].highlighted` | boolean |  |
| `trip.photos[].caption` | string or null |  |
| `trip.photos[].lat` | number or null |  |
| `trip.photos[].lng` | number or null |  |
| `trip.photos[].elevation` | integer or null |  |
| `trip.photos[].location` | string or null |  |
| `trip.photos[].locality` | string or null |  |
| `trip.photos[].administrative_area` | string or null |  |
| `trip.photos[].country_code` | string or null |  |
| `trip.photos[].created_at` | date-time |  |
| `trip.collections` | array of objects |  |
| `trip.collections[].id` | integer |  |
| `trip.collections[].user_id` | integer |  |
| `trip.collections[].url` | string |  |
| `trip.collections[].html_url` | string |  |
| `trip.collections[].visibility` | string |  |
| `trip.collections[].name` | string or null |  |
| `trip.collections[].description` | string or null |  |
| `trip.collections[].cover` | string or null |  |
| `trip.collections[].created_at` | date-time |  |
| `trip.collections[].updated_at` | date-time |  |

### Errors

- `401` Unauthorized
- `403` Forbidden - Trip not visible to user
- `404` Not Found - Trip not found

### Example request

```bash
curl \
  -H "x-rwgps-api-key: $API_KEY" \
  -H "x-rwgps-auth-token: $AUTH_TOKEN" \
  https://ridewithgps.com/api/v1/trips/123.json
```

### Example response

```json
{
  "trip": {
    "id": 123,
    "user_id": 123,
    "url": "https://ridewithgps.com/api/v1/trips/123.json",
    "html_url": "https://ridewithgps.com/trips/123",
    "visibility": "public",
    "name": "Forest Park loop",
    "description": "Morning ride through Forest Park",
    "departed_at": "2000-01-01T08:00:00-08:00",
    "time_zone": "America/Los_Angeles",
    "locality": "Portland",
    "administrative_area": "OR",
    "country_code": "US",
    "activity_type": "cycling:road",
    "fit_sport": 2,
    "fit_sub_sport": 7,
    "stationary": false,
    "distance": 40237,
    "duration": 7856,
    "moving_time": 7204,
    "elevation_gain": 457,
    "elevation_loss": 461,
    "first_lat": 45.521529,
    "first_lng": -122.691804,
    "last_lat": 45.521529,
    "last_lng": -122.691804,
    "sw_lat": 45.432536,
    "sw_lng": -122.836749,
    "ne_lat": 45.652881,
    "ne_lng": -122.471777,
    "track_type": "loop",
    "terrain": "rolling",
    "difficulty": "moderate",
    "avg_speed": 20.1,
    "max_speed": 52.3,
    "avg_cad": 87,
    "min_cad": 0,
    "max_cad": 119,
    "avg_hr": 143,
    "min_hr": 87,
    "max_hr": 177,
    "avg_watts": 183,
    "min_watts": 0,
    "max_watts": 627,
    "calories": 1318,
    "device": "Garmin Edge 840",
    "created_at": "2000-01-01T12:00:00Z",
    "updated_at": "2000-01-01T12:00:00Z",
    "track_points": [
      {
        "x": -122.691804,
        "y": 45.521529,
        "d": 12487.3,
        "e": 154,
        "t": 946744650,
        "s": 24.6,
        "T": 8,
        "h": 145,
        "c": 88,
        "p": 195,
        "pb": 51,
        "lap": false,
        "k": false,
        "m": false
      }
    ],
    "gear": {
      "id": 123,
      "make": "Specialized",
      "model": "Diverge",
      "description": "Gravel bike",
      "exclude_from_totals": false,
      "created_at": "2000-01-01T12:00:00Z"
    },
    "photos": [
      {
        "id": 123,
        "url": "https://ridewithgps.com/api/v1/photos/123/8275d8de285be31d7b2437bc3ae69756.jpg",
        "highlighted": false,
        "caption": "View from Pittock Mansion",
        "lat": 45.521529,
        "lng": -122.691804,
        "elevation": 290,
        "location": "Pittock Mansion",
        "locality": "Portland",
        "administrative_area": "OR",
        "country_code": "US",
        "created_at": "2000-01-01T12:00:00Z"
      }
    ],
    "collections": [
      {
        "id": 123,
        "user_id": 123,
        "url": "https://ridewithgps.com/api/v1/collections/123.json",
        "html_url": "https://ridewithgps.com/collections/123",
        "visibility": "public",
        "name": "Portland favorites",
        "description": "Our best rides around Portland",
        "cover": null,
        "created_at": "2000-01-01T12:00:00Z",
        "updated_at": "2000-01-01T12:00:00Z"
      }
    ]
  }
}
```

## Returns the polyline for the specified trip

`GET /api/v1/trips/{id}/polyline.json`

Returns a simplified polyline of the trip geometry, suitable for displaying on a map.
The `data` field is a Google Encoded Polyline.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `x-rwgps-api-key` | string | yes | API key for identifying the client application |
| `x-rwgps-auth-token` | string | yes | Authentication token for the user |

### Parameters

| Name | Type | In | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | integer | path | yes | Trip ID |
| `privacy_code` | string | query | no | Privacy code for the non public asset |

### Response `200`

| Name | Type | Description |
| --- | --- | --- |
| `polyline` | object |  |
| `polyline.parent_type` | string | Type of parent object (route or trip) |
| `polyline.parent_id` | integer | ID of the parent object |
| `polyline.data` | string or null | Google Encoded Polyline (precision 5, [latitude, longitude] order); simplified geometry. |

### Errors

- `401` Unauthorized
- `403` Forbidden - Trip not visible to user
- `404` Not Found - Trip not found

### Example request

```bash
curl \
  -H "x-rwgps-api-key: $API_KEY" \
  -H "x-rwgps-auth-token: $AUTH_TOKEN" \
  https://ridewithgps.com/api/v1/trips/123/polyline.json
```

### Example response

```json
{
  "polyline": {
    "parent_type": "route",
    "parent_id": 123,
    "data": "en`sFbhlaSiAoDlCaBa@mAWi@sBwC"
  }
}
```

## Downloads the specified trip as a GPS file

`GET /api/v1/trips/{id}.{format}`

Returns the trip as a GPS file, ready to load on a GPS device or into another application. The extension picks the format:

| Extension | Content type                           | File                                                                  |
|-----------|----------------------------------------|-----------------------------------------------------------------------|
| `gpx`     | `application/gpx+xml`                  | GPX 1.1 track at full resolution                                      |
| `tcx`     | `application/tcx+xml`                  | TCX activity history with heart rate, cadence and power when recorded |
| `fit`     | `application/vnd.ant.fit`              | FIT activity                                                          |
| `kml`     | `application/vnd.google-earth.kml+xml` | Google Earth track                                                    |

When the trip was uploaded as a FIT file and has not been edited since, the FIT download returns the original file as recorded by the device.

Track points are exported as the authenticated user is allowed to see them: points inside a privacy zone are only present for the trip owner, or when a valid `privacy_code` is given.

The file is sent as an attachment with a filename derived from the trip name. Visibility rules are the same as for the JSON record: a non public trip needs a `privacy_code` unless it belongs to the authenticated user.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `x-rwgps-api-key` | string | yes | API key for identifying the client application |
| `x-rwgps-auth-token` | string | yes | Authentication token for the user |

### Parameters

| Name | Type | In | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | integer | path | yes | Trip ID |
| `format` | string | path | yes | File format. One of: `gpx`, `tcx`, `fit`, `kml`. |
| `privacy_code` | string | query | no | Privacy code for the non public asset |

### Response `200`

GPS file

### Errors

- `401` Unauthorized
- `403` Forbidden - Trip not visible to user

### Example request

```bash
curl \
  -H "x-rwgps-api-key: $API_KEY" \
  -H "x-rwgps-auth-token: $AUTH_TOKEN" \
  https://ridewithgps.com/api/v1/trips/123.gpx
```

## Uploads a file to create trips

`POST /api/v1/trips.json`

Creates one or more trips from an uploaded GPS file. Accepted formats are GPX, TCX, KML and FIT.

**Multipart uploads**: This endpoint accepts only `Content-Type: multipart/form-data`. Send the
following fields:
- `file` - GPS file (binary), required
- `name` - Name for the created trip, otherwise taken from the file
- `description` - Description for the created trip
- `gear_id` - Gear to assign, must belong to the authenticated user

Processing happens in the background. The response is a task with `status: "pending"`,
and its `Location` header points at the task. Poll that url until `status` becomes
`completed`, then read the `items` array for the trips that were created and the
`errors` array for anything that failed.

A trip needs timestamps on its track points. A file without them, such as a planned
route, cannot be imported here and is reported with the `time_data_missing` error code.

Re-uploading a ride that already exists is reported with the `duplicate` error code, and
the error carries a reference to the existing trip.

Trip visibility always follows the account's default privacy setting for trips and
cannot be set through this endpoint.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `x-rwgps-api-key` | string | yes | API key for identifying the client application |
| `x-rwgps-auth-token` | string | yes | Authentication token for the user |

### Request body (`multipart/form-data`)

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | file | yes | GPS file |
| `name` | string | no | Name for the created trip, otherwise taken from the file |
| `description` | string | no | Description for the created trip |
| `gear_id` | integer | no | Gear to assign, must belong to the authenticated user |

### Response `202`

| Name | Type | Description |
| --- | --- | --- |
| `task` | object |  |
| `task.id` | integer |  |
| `task.user_id` | integer |  |
| `task.url` | string | API url of the task, to poll until it completes |
| `task.type` | string | What kind of work the task performs. `gps_file_upload` for uploads, `experience_package` for experience packages |
| `task.status` | string | `pending` until the task has run, then `completed` |
| `task.created_at` | date-time |  |
| `task.updated_at` | date-time |  |
| `task.items` | array of objects | Assets created by the task. Empty while pending, and empty if nothing was created. A file holding several tracks creates one asset per track |
| `task.items[].item_type` | string | Type of the created asset: `route` or `trip` for uploads, `experience_package` for experience packages |
| `task.items[].item_id` | integer |  |
| `task.items[].item_url` | string or null | API url of the created asset |
| `task.errors` | array of objects | Anything that went wrong, one entry per track that could not be imported. Empty when the task succeeded entirely |
| `task.errors[].code` | string | Machine readable reason. One of `duplicate`, `time_data_missing`, `no_tracks`, `empty_file`, `parse_failed`, `failed_to_process`, `weigh_in_failed`, `build_failed`, `error` |
| `task.errors[].message` | string | Human readable description, always in English |
| `task.errors[].item_type` | string or null | Set when the error refers to an existing asset, as for a duplicate |
| `task.errors[].item_id` | integer or null |  |
| `task.errors[].item_url` | string or null |  |

### Errors

- `400` No file provided
- `401` Unauthorized
- `422` Empty file or invalid parameter

### Example request

```bash
curl \
  -H "x-rwgps-api-key: $API_KEY" \
  -H "x-rwgps-auth-token: $AUTH_TOKEN" \
  -X POST \
  -F file=@route.gpx \
  -F name="Forest Park loop" \
  -F description="Morning ride through Forest Park" \
  -F gear_id="123" \
  https://ridewithgps.com/api/v1/trips.json
```

### Example response

```json
{
  "task": {
    "id": 123,
    "user_id": 123,
    "url": "https://ridewithgps.com/api/v1/tasks/123.json",
    "type": "gps_file_upload",
    "status": "completed",
    "created_at": "2000-01-01T12:00:00Z",
    "updated_at": "2000-01-01T12:00:00Z",
    "items": [
      {
        "item_type": "route",
        "item_id": 123,
        "item_url": "https://ridewithgps.com/api/v1/routes/123.json"
      }
    ],
    "errors": [
      {
        "code": "duplicate",
        "message": "This route already exists",
        "item_type": "route",
        "item_id": 123,
        "item_url": "https://ridewithgps.com/api/v1/routes/123.json"
      }
    ]
  }
}
```

## Copies the specified trip into your routes

`POST /api/v1/trips/{id}/copy.json`

Makes a route from a trip the authenticated user can see, in their own routes. The route
follows the trip's track, without its privacy zones, timestamps or sensor data.
Organizations can turn copying off for their trips.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `x-rwgps-api-key` | string | yes | API key for identifying the client application |
| `x-rwgps-auth-token` | string | yes | Authentication token for the user |

### Parameters

| Name | Type | In | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | integer | path | yes | Trip ID |
| `privacy_code` | string | query | no | Privacy code for the non public asset |

### Request body (`application/json`)

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `route` | object | no |  |
| `route.name` | string | no | Defaults to the original name. |
| `route.visibility` | string | no | Defaults to `private`, or `managers_only` for an organization. User-owned: `public`, `followers_only`, `mutual_followers_only` or `private`. Organization-owned: `public`, `members_only` or `managers_only`. See Visibilities. |

### Response `201`

| Name | Type | Description |
| --- | --- | --- |
| `route` | object |  |
| `route.id` | integer |  |
| `route.user_id` | integer |  |
| `route.url` | string |  |
| `route.html_url` | string |  |
| `route.visibility` | string |  |
| `route.name` | string |  |
| `route.description` | string or null |  |
| `route.locality` | string or null |  |
| `route.administrative_area` | string or null |  |
| `route.country_code` | string or null |  |
| `route.distance` | number | Distance in meters |
| `route.elevation_gain` | number | Elevation gain in meters |
| `route.elevation_loss` | number | Elevation loss in meters |
| `route.first_lat` | number |  |
| `route.first_lng` | number |  |
| `route.last_lat` | number |  |
| `route.last_lng` | number |  |
| `route.sw_lat` | number | Southwest bounding box latitude |
| `route.sw_lng` | number | Southwest bounding box longitude |
| `route.ne_lat` | number | Northeast bounding box latitude |
| `route.ne_lng` | number | Northeast bounding box longitude |
| `route.track_type` | string or null |  |
| `route.terrain` | string or null |  |
| `route.difficulty` | string or null |  |
| `route.unpaved_pct` | number or null |  |
| `route.surface` | string or null |  |
| `route.archived` | boolean or null | null for non owned routes |
| `route.created_at` | date-time |  |
| `route.updated_at` | date-time |  |

### Errors

- `400` Malformed body: route is not an object
- `401` Unauthorized
- `403` Forbidden - Trip not visible to user, or its organization turned copying off
- `404` Not Found - Trip not found
- `422` Invalid value

### Example request

```bash
curl \
  -H "x-rwgps-api-key: $API_KEY" \
  -H "x-rwgps-auth-token: $AUTH_TOKEN" \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
  "route": {
    "name": "Forest Park loop",
    "visibility": "private"
  }
}' \
  https://ridewithgps.com/api/v1/trips/123/copy.json
```

### Example response

```json
{
  "route": {
    "id": 123,
    "user_id": 123,
    "url": "https://ridewithgps.com/api/v1/routes/123.json",
    "html_url": "https://ridewithgps.com/routes/123",
    "visibility": "public",
    "name": "Forest Park loop",
    "description": "Morning ride through Forest Park",
    "locality": "Portland",
    "administrative_area": "OR",
    "country_code": "US",
    "distance": 40237,
    "elevation_gain": 457,
    "elevation_loss": 461,
    "first_lat": 45.521529,
    "first_lng": -122.691804,
    "last_lat": 45.521529,
    "last_lng": -122.691804,
    "sw_lat": 45.432536,
    "sw_lng": -122.836749,
    "ne_lat": 45.652881,
    "ne_lng": -122.471777,
    "track_type": "loop",
    "terrain": "rolling",
    "difficulty": "moderate",
    "unpaved_pct": 12,
    "surface": "mostly_paved",
    "archived": false,
    "created_at": "2000-01-01T12:00:00Z",
    "updated_at": "2000-01-01T12:00:00Z"
  }
}
```

## Updates the specified trip

`PUT /api/v1/trips/{id}.json`

Updates details of a trip owned by the authenticated user. Only the fields sent are
changed. The track cannot be changed.

Any invalid value returns a 422 and nothing is saved. Values of the wrong type, such as an
object for `name`, may be ignored.

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `x-rwgps-api-key` | string | yes | API key for identifying the client application |
| `x-rwgps-auth-token` | string | yes | Authentication token for the user |

### Parameters

| Name | Type | In | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | integer | path | yes | Trip ID |

### Request body (`application/json`)

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `trip` | object | yes |  |
| `trip.name` | string or null | no | null or empty resets the name to its default. |
| `trip.description` | string or null | no | At most 16,000 characters. |
| `trip.visibility` | string | no | User-owned: `public`, `followers_only`, `mutual_followers_only` or `private`. Organization-owned: `public`, `members_only` or `managers_only`. See Visibilities. |
| `trip.activity_type` | string | no | See Activity Types. One of: `other:generic`, `cycling:generic`, `cycling:road`, `cycling:gravel`, `cycling:cyclocross`, `cycling:mountain`, `cycling:recumbent`, `cycling:hand_cycling`, `cycling:commute`, `cycling:indoor`, `cycling:virtual`, `e_biking:generic`, `e_biking:road`, `e_biking:mountain`, `running:generic`, `running:road`, `running:trail`, `running:indoor`, `walking:generic`, `walking:hiking`, `walking:indoor`, `walking:speed`, `swimming:generic`, `swimming:lap`, `swimming:open_water`, `snow:generic`, `snow:alpine_skiing`, `snow:cross_country_skiing`, `snow:snowboarding`, `snow:snowshoeing`, `driving:generic`, `motorcycling:generic`, `motorcycling:atv`, `motorcycling:motocross`, `training:generic`, `training:strength`, `training:cardio`, `training:breathing`, `training:yoga`, `training:hiit`. |

### Response `200`

| Name | Type | Description |
| --- | --- | --- |
| `trip` | object |  |
| `trip.id` | integer |  |
| `trip.user_id` | integer |  |
| `trip.url` | string |  |
| `trip.html_url` | string |  |
| `trip.visibility` | string |  |
| `trip.name` | string |  |
| `trip.description` | string or null |  |
| `trip.departed_at` | date-time or null |  |
| `trip.time_zone` | string or null |  |
| `trip.locality` | string or null |  |
| `trip.administrative_area` | string or null |  |
| `trip.country_code` | string or null |  |
| `trip.activity_type` | string or null |  |
| `trip.fit_sport` | integer or null |  |
| `trip.fit_sub_sport` | integer or null |  |
| `trip.stationary` | boolean |  |
| `trip.distance` | number | Distance in meters |
| `trip.duration` | number | Duration in seconds |
| `trip.moving_time` | number | Moving time in seconds |
| `trip.elevation_gain` | number | Elevation gain in meters |
| `trip.elevation_loss` | number | Elevation loss in meters |
| `trip.first_lat` | number or null |  |
| `trip.first_lng` | number or null |  |
| `trip.last_lat` | number or null |  |
| `trip.last_lng` | number or null |  |
| `trip.sw_lat` | number or null |  |
| `trip.sw_lng` | number or null |  |
| `trip.ne_lat` | number or null |  |
| `trip.ne_lng` | number or null |  |
| `trip.track_type` | string or null |  |
| `trip.terrain` | string or null |  |
| `trip.difficulty` | string or null |  |
| `trip.avg_speed` | number or null | Average speed in kilometers per hour |
| `trip.max_speed` | number or null | Maximum speed in kilometers per hour |
| `trip.avg_cad` | number or null | Average cadence in rounds per minute |
| `trip.min_cad` | number or null | Minimum cadence in rounds per minute |
| `trip.max_cad` | number or null | Maximum cadence in rounds per minute |
| `trip.avg_hr` | number or null | Average heart rate in beats per minute |
| `trip.min_hr` | number or null | Minimum heart rate in beats per minute |
| `trip.max_hr` | number or null | Maximum heart rate in beats per minute |
| `trip.avg_watts` | number or null | Average power in watts |
| `trip.min_watts` | number or null | Minimum power in watts |
| `trip.max_watts` | number or null | Maximum power in watts |
| `trip.calories` | number or null | Calories burned |
| `trip.device` | string or null |  |
| `trip.created_at` | date-time |  |
| `trip.updated_at` | date-time |  |
| `trip.track_points` | array of objects |  |
| `trip.track_points[].x` | number | Longitude |
| `trip.track_points[].y` | number | Latitude |
| `trip.track_points[].d` | number | Distance from start in meters |
| `trip.track_points[].e` | integer | Elevation in meters |
| `trip.track_points[].t` | integer | Unix epoch time in seconds |
| `trip.track_points[].s` | number | Speed in kilometers per hour |
| `trip.track_points[].T` | integer | Temperature in degrees celsius |
| `trip.track_points[].h` | integer | Heart rate in beats per minute |
| `trip.track_points[].c` | integer | Cadence in rounds per minute |
| `trip.track_points[].p` | integer | Power output in watts |
| `trip.track_points[].pb` | integer | Power balance percent L/R |
| `trip.track_points[].lap` | boolean | Start of lap |
| `trip.track_points[].k` | boolean | Exclude from metrics |
| `trip.track_points[].m` | boolean | User modified |
| `trip.gear` | object |  |
| `trip.gear.id` | integer |  |
| `trip.gear.make` | string or null |  |
| `trip.gear.model` | string or null |  |
| `trip.gear.description` | string or null |  |
| `trip.gear.exclude_from_totals` | boolean |  |
| `trip.gear.created_at` | date-time |  |
| `trip.photos` | array of objects |  |
| `trip.photos[].id` | integer |  |
| `trip.photos[].url` | string |  |
| `trip.photos[].highlighted` | boolean |  |
| `trip.photos[].caption` | string or null |  |
| `trip.photos[].lat` | number or null |  |
| `trip.photos[].lng` | number or null |  |
| `trip.photos[].elevation` | integer or null |  |
| `trip.photos[].location` | string or null |  |
| `trip.photos[].locality` | string or null |  |
| `trip.photos[].administrative_area` | string or null |  |
| `trip.photos[].country_code` | string or null |  |
| `trip.photos[].created_at` | date-time |  |
| `trip.collections` | array of objects |  |
| `trip.collections[].id` | integer |  |
| `trip.collections[].user_id` | integer |  |
| `trip.collections[].url` | string |  |
| `trip.collections[].html_url` | string |  |
| `trip.collections[].visibility` | string |  |
| `trip.collections[].name` | string or null |  |
| `trip.collections[].description` | string or null |  |
| `trip.collections[].cover` | string or null |  |
| `trip.collections[].created_at` | date-time |  |
| `trip.collections[].updated_at` | date-time |  |

### Errors

- `400` Empty body
- `401` Unauthorized
- `403` Forbidden - cannot update trip owned by another user
- `404` Trip not found
- `422` Invalid value

### Example request

```bash
curl \
  -H "x-rwgps-api-key: $API_KEY" \
  -H "x-rwgps-auth-token: $AUTH_TOKEN" \
  -X PUT \
  -H "Content-Type: application/json" \
  -d '{
  "trip": {
    "name": "Forest Park loop",
    "description": "Morning ride through Forest Park",
    "visibility": "public",
    "activity_type": "cycling:road"
  }
}' \
  https://ridewithgps.com/api/v1/trips/123.json
```

### Example response

```json
{
  "trip": {
    "id": 123,
    "user_id": 123,
    "url": "https://ridewithgps.com/api/v1/trips/123.json",
    "html_url": "https://ridewithgps.com/trips/123",
    "visibility": "public",
    "name": "Forest Park loop",
    "description": "Morning ride through Forest Park",
    "departed_at": "2000-01-01T08:00:00-08:00",
    "time_zone": "America/Los_Angeles",
    "locality": "Portland",
    "administrative_area": "OR",
    "country_code": "US",
    "activity_type": "cycling:road",
    "fit_sport": 2,
    "fit_sub_sport": 7,
    "stationary": false,
    "distance": 40237,
    "duration": 7856,
    "moving_time": 7204,
    "elevation_gain": 457,
    "elevation_loss": 461,
    "first_lat": 45.521529,
    "first_lng": -122.691804,
    "last_lat": 45.521529,
    "last_lng": -122.691804,
    "sw_lat": 45.432536,
    "sw_lng": -122.836749,
    "ne_lat": 45.652881,
    "ne_lng": -122.471777,
    "track_type": "loop",
    "terrain": "rolling",
    "difficulty": "moderate",
    "avg_speed": 20.1,
    "max_speed": 52.3,
    "avg_cad": 87,
    "min_cad": 0,
    "max_cad": 119,
    "avg_hr": 143,
    "min_hr": 87,
    "max_hr": 177,
    "avg_watts": 183,
    "min_watts": 0,
    "max_watts": 627,
    "calories": 1318,
    "device": "Garmin Edge 840",
    "created_at": "2000-01-01T12:00:00Z",
    "updated_at": "2000-01-01T12:00:00Z",
    "track_points": [
      {
        "x": -122.691804,
        "y": 45.521529,
        "d": 12487.3,
        "e": 154,
        "t": 946744650,
        "s": 24.6,
        "T": 8,
        "h": 145,
        "c": 88,
        "p": 195,
        "pb": 51,
        "lap": false,
        "k": false,
        "m": false
      }
    ],
    "gear": {
      "id": 123,
      "make": "Specialized",
      "model": "Diverge",
      "description": "Gravel bike",
      "exclude_from_totals": false,
      "created_at": "2000-01-01T12:00:00Z"
    },
    "photos": [
      {
        "id": 123,
        "url": "https://ridewithgps.com/api/v1/photos/123/8275d8de285be31d7b2437bc3ae69756.jpg",
        "highlighted": false,
        "caption": "View from Pittock Mansion",
        "lat": 45.521529,
        "lng": -122.691804,
        "elevation": 290,
        "location": "Pittock Mansion",
        "locality": "Portland",
        "administrative_area": "OR",
        "country_code": "US",
        "created_at": "2000-01-01T12:00:00Z"
      }
    ],
    "collections": [
      {
        "id": 123,
        "user_id": 123,
        "url": "https://ridewithgps.com/api/v1/collections/123.json",
        "html_url": "https://ridewithgps.com/collections/123",
        "visibility": "public",
        "name": "Portland favorites",
        "description": "Our best rides around Portland",
        "cover": null,
        "created_at": "2000-01-01T12:00:00Z",
        "updated_at": "2000-01-01T12:00:00Z"
      }
    ]
  }
}
```

## Deletes the specified trip

`DELETE /api/v1/trips/{id}.json`

Deletes a trip owned by the authenticated user

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `x-rwgps-api-key` | string | yes | API key for identifying the client application |
| `x-rwgps-auth-token` | string | yes | Authentication token for the user |

### Parameters

| Name | Type | In | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | integer | path | yes | Trip ID |

### Response `204`

Trip deleted successfully

### Errors

- `401` Unauthorized
- `403` Forbidden - cannot delete trip owned by another user
- `404` Trip not found

### Example request

```bash
curl \
  -H "x-rwgps-api-key: $API_KEY" \
  -H "x-rwgps-auth-token: $AUTH_TOKEN" \
  -X DELETE \
  https://ridewithgps.com/api/v1/trips/123.json
```
