· View as Markdown

Sync

Returns items for sync

GET /api/v1/sync.json

Returns a list of items (routes and/or trips) that the user has interacted with since the given datetime.

The sync endpoint is convenient to maintain a remote copy of a user's library of trips and/or routes.

Actions

Items can have the following actions: * created - The user created the item * updated - The user updated the item * deleted - The user deleted the item * added - The user added the item to the specified collection (e.g., pinned) * removed - The user removed the item from the specified collection

For added and removed actions, collection is the target collection where the action was taken. It is currently always the collection of pinned items for the authenticated user, but we might expose other collections in the future.

Sync Workflow

This endpoint is optimized for performance (we use a similar setup for syncing our own mobile apps), and can return the entire library for the user by using a since value well in the past (for example 1970-01-01).

The following workflow is suitable to maintain your copy of a user's library:

  1. When the user finalizes the OAuth workflow, get the current content of their library at GET https://ridewithgps.com/api/v1/sync.json?since=1970-01-01
  2. Download and integrate in your system every item in the response and store the value of the meta.rwgps_datetime key in the response
  3. Upon reception of a webhook for the user, get and integrate the items that have changed from a new sync request at GET https://ridewithgps.com/api/v1/sync.json?since=[rwgps_datetime]. Store the new value of meta.rwgps_datetime for the next sync request.

Doing a sync request on webhook reception instead of processing the items in the body of the webhook leads to the same result and provides a recovery mechanism for previous webhooks that might have failed because of network or systems availability issues.

Headers

  • x-rwgps-api-key string required
    API key for identifying the client application
  • x-rwgps-auth-token string required
    Authentication token for the user

Parameters

  • since string query required
    ISO 8601 datetime string for last sync. Use 1970-01-01 for initial sync to get entire library.
  • assets string query
    Comma-separated list of asset types to return (routes, trips). Defaults to your API client setting.
    One of: routes, trips, routes,trips

Response 200

  • items array of objects
    Array of sync items representing changes since the specified datetime
    7 fields
    • item_type string
      Type of item
      One of: route, trip
    • item_id integer
      ID of the item
    • item_user_id integer
      ID of the user who owns the item. It will be the ID of the authenticated user for created, updated and deleted actions. It might point to another user for added and removed actions, when the authenticated user pins an item from another user.
    • item_url string
      API URL for the item
    • action string
      Action performed on the item
      One of: created, updated, deleted, added, removed
    • datetime string
      When the action occurred
    • collection object or null
      Collection context for added/removed actions (null for other actions)
      4 fields
      • id integer
      • type string
      • name string
      • url string
  • meta object
    2 fields
    • rwgps_datetime string
      Current server timestamp - use this value for the next sync request
    • next_sync_url string
      Pre-formatted URL for the next sync request with proper datetime

Errors

  • 401 Unauthorized
Request
curl \
  -H "x-rwgps-api-key: $API_KEY" \
  -H "x-rwgps-auth-token: $AUTH_TOKEN" \
  https://ridewithgps.com/api/v1/sync.json
Response 200
{
  "items": [
    {
      "item_type": "route",
      "item_id": 123,
      "item_user_id": 123,
      "item_url": "https://ridewithgps.com/api/v1/routes/123.json",
      "action": "created",
      "datetime": "2000-01-01T11:45:00+00:00",
      "collection": {
        "id": 123,
        "type": "pinned",
        "name": "Pinned",
        "url": "https://ridewithgps.com/api/v1/collections/123.json"
      }
    }
  ],
  "meta": {
    "rwgps_datetime": "2000-01-01T12:00:00+00:00",
    "next_sync_url": "https://ridewithgps.com/api/v1/sync.json?assets=routes%2Ctrips&since=2000-01-01T12%3A00%3A00%2B00%3A00"
  }
}