Skip to main content

Developer API

Trail intelligence for hikers and planning tools.

TrailIntel turns hazards and conditions into human-readable hiking guidance for the website. Developers and robotics engineers can use the GraphQL API to retrieve the same route, traversability, and hazard signals as structured planning payloads.

GraphQL operations

Field names use GraphQL camelCase (for example trailHazardsGeojson). The backend is Strawberry on FastAPI; you can open the GraphQL URL in a browser while the server is running to use GraphiQL and explore the live schema.

NameTypePurpose
searchTrailsByNameQueryText search with optional location filters (state, city, park type, park name).
trailQuerySingle trail by numeric id, including location when available.
nearbyTrailsQueryTrails near a point within a radius (km), with the same optional filters as search.
trailConditionsQueryConditions bundle: hazards, weather snapshot, seasonal intel, reports.
trailHazardsQueryActive or all hazards for a trail.
trailHazardsGeojsonQueryHazard features as GeoJSON for map overlays.
trailReviewsQueryRecent reviews for a trail.
roboticsTraversabilityQueryPre-mission robotics payload: scores, route GeoJSON, ROS-shaped route, costs, planning notes.
roboticsAreaQueryRadius-based area summary: trail candidates, risk density, recommended trail ids.
submitReportMutationSubmit a trail condition report (rate limits may apply).
upvoteReportMutationUpvote a community report.
resolveReportMutationMark a report resolved (moderation / internal use).

Endpoint and quick start

Send POST requests with a JSON body { "query", "variables" } to https://trailintel-api.onrender.com/graphql. The web app uses the same URL via NEXT_PUBLIC_GRAPHQL_URL (defaults to local development if unset).

Use roboticsTraversability for one trail mission payload and roboticsArea for radius-level mission screening.

curl -s -X POST https://trailintel-api.onrender.com/graphql \
  -H "Content-Type: application/json" \
  -d '{"query":"query($trailId:Int!){ roboticsTraversability(trailId:$trailId){ trailId name riskScore traversabilityScore effortScore hazardLocationQuality geometryQuality geometrySource vertexCount planningNotes rosCompatibleRoute segmentCosts elevationProfile costModel hazardSummary { activeCount highestSeverity types } dataFreshness { generatedAt latestHazardAt sourceCount stale } }}","variables":{"trailId":1}}'
curl -s -X POST https://trailintel-api.onrender.com/graphql \
  -H "Content-Type: application/json" \
  -d '{"query":"query($lat:Float!,$lng:Float!,$radiusM:Float!){ roboticsArea(lat:$lat,lng:$lng,radiusM:$radiusM){ center { lat lng } radiusM activeHazardCount hazardDensity areaRiskScore highestRiskTrail { trailId name riskScore } recommendedTrailIds trails { trailId name riskScore traversabilityScore effortScore activeHazardCount hazardLocationQuality } generatedAt }}","variables":{"lat":47.414,"lng":-121.428,"radiusM":40000}}'

Responses and errors

Successful calls return JSON with a data key. GraphQL errors appear in an errors array (validation, resolver failures, rate limits on mutations). Always check errors before assuming data is complete.

{
  "data": { "trail": { "id": 1, "name": "…" } },
  "errors": [{ "message": "…" }]
}

Call the API from the same origin as this site, or from tools like curl, without extra headers beyond Content-Type: application/json. If you embed the endpoint in another web origin, ensure the backend CORS settings allow that origin.

What the API provides

The public GraphQL surface exposes trail search, nearby trail discovery, trail conditions, active hazards, reviews, and robotics-facing traversability payloads. The robotics payload is intended for pre-mission context: route geometry, route-level costs, traversability scores, and planning notes.

It is not robot control, autonomous navigation, SLAM, or real-time obstacle avoidance.

Trail overview (hiker / product)

This is the same shape the frontend uses for trail detail: core trail facts plus the conditions card payload.

query TrailOverview($trailId: Int!) {
  trail(id: $trailId) {
    id
    name
    region
    lengthKm
    elevationGainM
  }
  trailConditions(trailId: $trailId) {
    overallScore
    hazardSummary {
      activeCount
      highestSeverity
      types
    }
    weatherSnapshot {
      summary
      temperatureC
    }
  }
}
curl -s -X POST https://trailintel-api.onrender.com/graphql \
  -H "Content-Type: application/json" \
  -d '{"query":"query($trailId:Int!){ trail(id:$trailId){ id name region lengthKm elevationGainM } trailConditions(trailId:$trailId){ overallScore hazardSummary{ activeCount highestSeverity types } weatherSnapshot{ summary temperatureC } } }","variables":{"trailId":1}}'

Robotics traversability query

Call the backend GraphQL endpoint with a trail id to retrieve a robotics planning payload.

query RoboticsTraversability($trailId: Int!) {
  roboticsTraversability(trailId: $trailId) {
    trailId
    name
    traversabilityScore
    riskScore
    effortScore
    geometryQuality
    geometrySource
    vertexCount
    hazardLocationQuality
    routeGeojson
    hazardsGeojson
    hazardSummary {
      activeCount
      highestSeverity
      types
    }
    dataFreshness {
      generatedAt
      latestHazardAt
      sourceCount
      stale
    }
    rosCompatibleRoute
    segmentCosts
    elevationProfile
    costModel
    planningNotes
  }
}

Area screening query

Use this query to compare nearby trails, inspect area risk density, and pick lower-risk candidate trail ids.

query RoboticsArea($lat: Float!, $lng: Float!, $radiusM: Float!) {
  roboticsArea(lat: $lat, lng: $lng, radiusM: $radiusM) {
    center {
      lat
      lng
    }
    radiusM
    activeHazardCount
    hazardDensity
    areaRiskScore
    highestRiskTrail {
      trailId
      name
      riskScore
      activeHazardCount
      hazardLocationQuality
    }
    recommendedTrailIds
    trails {
      trailId
      name
      traversabilityScore
      riskScore
      effortScore
      activeHazardCount
      hazardLocationQuality
    }
    generatedAt
  }
}

Example data excerpt:

{
  "roboticsArea": {
    "center": {
      "lat": 47.414,
      "lng": -121.428
    },
    "radiusM": 40000,
    "activeHazardCount": 3,
    "hazardDensity": 0.597,
    "areaRiskScore": 0.347,
    "highestRiskTrail": {
      "trailId": 3,
      "name": "Mailbox Peak Trail",
      "riskScore": 0.52,
      "activeHazardCount": 1,
      "hazardLocationQuality": "trail_level"
    },
    "recommendedTrailIds": [2, 1],
    "trails": [
      {
        "trailId": 2,
        "name": "Rattlesnake Ledge",
        "traversabilityScore": 0.78,
        "riskScore": 0.26,
        "effortScore": 0.31,
        "activeHazardCount": 0,
        "hazardLocationQuality": "unknown"
      },
      {
        "trailId": 1,
        "name": "Snow Lake Trail",
        "traversabilityScore": 0.72,
        "riskScore": 0.31,
        "effortScore": 0.41,
        "activeHazardCount": 2,
        "hazardLocationQuality": "trail_level"
      }
    ],
    "generatedAt": "2026-04-29T06:00:00Z"
  }
}

ROS-compatible message format

rosCompatibleRoute is JSON shaped like a ROS route message, with header.frame_id, route poses, and per-pose costs. It does not require a ROS runtime.

{
  "roboticsTraversability": {
    "trailId": 1,
    "name": "Snow Lake Trail",
    "geometryQuality": "synthetic",
    "geometrySource": "seed.sql",
    "vertexCount": 2,
    "hazardLocationQuality": "trail_level",
    "hazardsGeojson": {
      "type": "FeatureCollection",
      "features": []
    },
    "dataFreshness": {
      "generatedAt": "2026-04-29T06:00:00Z",
      "latestHazardAt": "2026-04-28T12:00:00Z",
      "sourceCount": 2,
      "stale": false
    },
    "rosCompatibleRoute": {
      "header": {
        "frame_id": "map",
        "generated_at": "2026-04-29T06:00:00Z",
        "coordinate_system": "WGS84",
        "axes": {
          "x": "longitude_degrees",
          "y": "latitude_degrees",
          "z": "elevation_meters"
        }
      },
      "poses": [
        {
          "position": {
            "x": -121.52,
            "y": 47.445,
            "z": 0.0
          },
          "orientation": {
            "x": 0.0,
            "y": 0.0,
            "z": 0.0,
            "w": 1.0
          }
        }
      ],
      "costs": [0.31]
    },
    "segmentCosts": [
      {
        "index": 0,
        "estimated_gain_m": 38.4,
        "estimated_grade": 0.1412,
        "hazard_component": 0.31,
        "cost": 0.27
      },
      {
        "index": 1,
        "estimated_gain_m": 55.7,
        "estimated_grade": 0.2038,
        "hazard_component": 0.31,
        "cost": 0.33
      }
    ],
    "elevationProfile": [
      { "index": 0, "distance_ratio": 0.0, "elevation_m": 0.0 },
      { "index": 1, "distance_ratio": 0.091, "elevation_m": 38.4 },
      { "index": 2, "distance_ratio": 0.182, "elevation_m": 94.1 }
    ],
    "costModel": {
      "version": "v2-segment-aware",
      "fallback_mode": true,
      "weights": {
        "traversability": 0.35,
        "hazard": 0.4,
        "segment_effort": 0.25
      }
    },
    "planningNotes": [
      "ROS-compatible message format generated from route geometry for pre-mission planning.",
      "Route pose coordinates are geographic (WGS84 lon/lat), not local ENU map meters.",
      "Active hazards are treated as route-level risk because exact hazard GPS points are not available."
    ]
  }
}

Quality and provenance fields

geometryQuality

Describes the route geometry provenance level, such as synthetic demo data, curated project data, or a future imported GIS source.

geometrySource

Names the source label or URL behind the route geometry. Current seeded routes are simplified and should not be treated as survey-grade.

vertexCount

Counts original route vertices before interpolation. A two-vertex route may still produce more poses in the ROS-compatible message format.

hazardLocationQuality

Explains whether hazards have exact point coordinates. Current MVP hazards are often trail-level risk unless a hazard row has a real location.

rosCompatibleRoute.header.coordinate_system

Identifies the route coordinate reference. Current route poses use WGS84 lon/lat values in x/y and should be transformed before local planner execution.

effortScore / segmentCosts / elevationProfile

These fields expose effort and per-segment cost context. Costs are segment-aware when geometry/elevation detail exists, and marked as fallback mode when source detail is limited.

How to read the robotics payload

Treat hazards as route-level risk unless hazardLocationQuality is exact. Current seeded route geometry is simplified demo geometry, so clients should use geometryQuality, geometrySource, and vertexCount when deciding whether a route is suitable for a downstream planner. rosCompatibleRoute points are currently lon/lat in WGS84, so transform coordinates into your robot map frame before execution. hazardsGeojson only includes exact point features when a hazard row has real coordinates.

Client fetch example

This fetch pattern matches the backend GraphQL contract and can be used by mission-planning tooling. Replace the URL with your deployed NEXT_PUBLIC_GRAPHQL_URL when not running locally.

const response = await fetch("https://trailintel-api.onrender.com/graphql", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    query: `query($trailId:Int!){
      roboticsTraversability(trailId:$trailId){
        trailId
        name
        riskScore
        rosCompatibleRoute
        planningNotes
      }
    }`,
    variables: { trailId: 1 }
  })
});

const payload = await response.json();
console.log(payload.data.roboticsTraversability);