Guides
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
- searchingno_driver
- driver_assignedcancelled
- driver_arrivedcancelled
- started
- completed
trip.driver_assignedMoves the trip todriver_assignedAccepted when the trip issearching, or driver_assigned (reassign before pickup)trip.driver_arrivedMoves the trip todriver_arrivedAccepted when the trip isdriver_assignedtrip.startedMoves the trip tostartedAccepted when the trip isdriver_assigned or driver_arrived, with the rightpintrip.completedMoves the trip tocompletedAccepted when the trip isstartedtrip.cancelledMoves the trip tocancelledtrip.no_driverMoves the trip tono_driverAccepted when the trip issearchingtrip.driver_locationMoves the trip toNo changeAccepted when the trip isAny time before it endstrip.arrived_at_stop,trip.departed_stopMoves the trip toNo changeAccepted when the trip isstartedtrip.rider_ratedMoves the trip toNo changeAccepted when the trip iscompleted
| Event | Moves the trip to | Accepted when the trip is |
|---|---|---|
trip.driver_assigned | driver_assigned | searching, or driver_assigned (reassign before pickup) |
trip.driver_arrived | driver_arrived | driver_assigned |
trip.started | started | driver_assigned or driver_arrived, with the right pin |
trip.completed | completed | started |
trip.cancelled | cancelled | Any time before it ends (cash trips have limits, see Cash trips) |
trip.no_driver | no_driver | searching |
trip.driver_location | No change | Any time before it ends |
trip.arrived_at_stop, trip.departed_stop | No change | started |
trip.rider_rated | No change | completed |
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.completedbeforetrip.started) gets 409retry_laterand 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_ratedis taken (after completed). occurred_atmore than 60 seconds before we booked the trip gets 400invalid_event. It is kept as you sent it; the completion time we record is our own clock.
Our answers
- 200
{ "ok": true, "result": "applied" }MeaningDoneYouStop - 200
result: "duplicate"MeaningWe already have thisevent_idYouStop - 200
result: "ignored"MeaningThe trip is already past this stateYouStop - 409
retry_laterMeaningIt came before an earlier event, or the trip was busyYouRetry with backoff - 422
wrong_pinMeaningWrong rider code ontrip.startedYouAsk the driver again, send a new event - 409
complete_required,cancel_not_allowed, 422fee_not_supportedMeaningCash cancel rules - 400, 401, 403, 404, 411, 413MeaningFix the request
- 429, 5xx, timeoutMeaningOur sideYouRetry with backoff
| Our answer | Meaning | You |
|---|---|---|
200 { "ok": true, "result": "applied" } | Done | Stop |
200 result: "duplicate" | We already have this event_id | Stop |
200 result: "ignored" | The trip is already past this state | Stop |
409 retry_later | It came before an earlier event, or the trip was busy | Retry with backoff |
422 wrong_pin | Wrong rider code on trip.started | Ask the driver again, send a new event |
409 complete_required, cancel_not_allowed, 422 fee_not_supported | Cash cancel rules | See Cash trips |
| 400, 401, 403, 404, 411, 413 | Fix the request | Do not retry unchanged. See Errors |
| 429, 5xx, timeout | Our side | Retry 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-Lengthheader. - 1,200 events a minute per partner. Over that: 429 with
Retry-After.