Skip to content

Trip events

Tell PerfectRide what happens on each trip, in order, and handle our answers.

POST each event to the events URL, signed with path /events. Every event has event, event_id (unique per event), partner_trip_id, pr_trip_id and occurred_at. The full list is in Events you send.

Lifecycle

  1. searchingno_driver
  2. driver_assignedcancelled
  3. driver_arrivedcancelled
  4. started
  5. completed
  • trip.driver_assigned
    Moves the trip todriver_assigned
    Accepted when the trip issearching, or driver_assigned (reassign before pickup)
  • trip.driver_arrived
    Moves the trip todriver_arrived
    Accepted when the trip isdriver_assigned
  • trip.started
    Moves the trip tostarted
    Accepted when the trip isdriver_assigned or driver_arrived, with the right pin
  • trip.completed
    Moves the trip tocompleted
    Accepted when the trip isstarted
  • trip.cancelled
    Moves the trip tocancelled
    Accepted when the trip isAny time before it ends (cash trips have limits, see Cash trips)
  • trip.no_driver
    Moves the trip tono_driver
    Accepted when the trip issearching
  • trip.driver_location
    Moves the trip toNo change
    Accepted when the trip isAny time before it ends
  • trip.arrived_at_stop, trip.departed_stop
    Moves the trip toNo change
    Accepted when the trip isstarted
  • trip.rider_rated
    Moves the trip toNo change
    Accepted when the trip iscompleted

Send one

TS=$(date +%s)
NOW=$(date -u +%Y-%m-%dT%H:%M:%SZ)
PR_TRIP_ID=pr_xxxx   # the test trip from the portal
BODY='{"event":"trip.driver_assigned","event_id":"ev_0001","partner_trip_id":"t_9931","pr_trip_id":"'"$PR_TRIP_ID"'","occurred_at":"'"$NOW"'","driver":{"id":"d_771","name":"Musa A.","phone":"+2348090001122"},"vehicle":{"make":"Toyota","model":"Corolla","color":"Black","plate":"PHC-123-AB"},"eta_seconds":240}'
SIG=$(printf '%s' "$TS.POST./events.$BODY" | openssl dgst -sha256 -hmac "$PR_SECRET" | sed 's/^.*= //')

curl https://www.perfectride.io/api/partner/v1/events \
  -H "Authorization: Bearer $PR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-PR-Timestamp: $TS" \
  -H "X-PR-Signature: sha256=$SIG" \
  --data-raw "$BODY"

Ordering

  • Send events in the order they happened. Trips only move forward.
  • An event that arrives before the one it follows (for example trip.completed before trip.started) gets 409 retry_later and is not recorded. Send the earlier event, then retry.
  • An event for a state the trip has already passed gets 200 with result: "ignored".
  • Once a trip is completed, cancelled or no_driver, only trip.rider_rated is taken (after completed).
  • occurred_at more than 60 seconds before we booked the trip gets 400 invalid_event. It is kept as you sent it; the completion time we record is our own clock.

Our answers

  • 200 { "ok": true, "result": "applied" }
    MeaningDone
    YouStop
  • 200 result: "duplicate"
    MeaningWe already have this event_id
    YouStop
  • 200 result: "ignored"
    MeaningThe trip is already past this state
    YouStop
  • 409 retry_later
    MeaningIt came before an earlier event, or the trip was busy
    YouRetry with backoff
  • 422 wrong_pin
    MeaningWrong rider code on trip.started
    YouAsk the driver again, send a new event
  • 409 complete_required, cancel_not_allowed, 422 fee_not_supported
    MeaningCash cancel rules
    YouSee Cash trips
  • 400, 401, 403, 404, 411, 413
    MeaningFix the request
    YouDo not retry unchanged. See Errors
  • 429, 5xx, timeout
    MeaningOur side
    YouRetry with backoff
Tip: Backoff: start at 1 second and double, up to 1 hour between tries, for 24 hours. Keep the same event_id on every retry so a repeat is a duplicate, never a second event.

Limits

  • 64 KB per event, with a Content-Length header.
  • 1,200 events a minute per partner. Over that: 429 with Retry-After.

View this page as Markdown · hello@perfectride.io