Rydmate API
Rydmate PHP API
Connect your PHP application to Rydmate: read the fleet, hold seats and hear about every change. There is no separate library to install. The API speaks plain HTTPS and JSON, so PHP's own tools are enough.
Before you start
- Create an API key in Rydmate under Developers. A key starting with
ryd_test_works on your test account, so nothing you try touches real trips or money. - Set it as
RYDMATE_API_KEYin your environment. Never put the key in your code or your app. - No packages to install: curl and hash_hmac come with PHP.
List your vehicles
The simplest request: every vehicle in the business, with its registration and status. If something goes wrong, the error says what, and carries a reference our team can look up.
<?php
$api = getenv('RYDMATE_API_URL') ?: 'https://api.rydmate.com/api/v1';
$ch = curl_init("$api/vehicles");
curl_setopt_array($ch, [
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('RYDMATE_API_KEY')],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
]);
$body = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($status >= 400) {
$e = $body['error'];
throw new RuntimeException("{$e['code']}: {$e['message']} ({$e['request_id']})");
}
foreach ($body['data'] as $vehicle) {
echo $vehicle['registration_number'], ' ', $vehicle['status'], PHP_EOL;
}Run it with php list.php.
Hold a seat without double bookings
Hold a seat on a departure for a passenger. The Idempotency-Key header means that if the connection drops and you send the same request again, you still get one hold, not two.
If another counter took the seat first, Rydmate answers with a conflict instead of booking it twice. Once the passenger has paid, confirm the hold with POST /bookings/{id}/transition and {"to": "CONFIRMED"}.
<?php
$api = getenv('RYDMATE_API_URL') ?: 'https://api.rydmate.com/api/v1';
$tripId = getenv('TRIP_ID');
$ch = curl_init("$api/trips/$tripId/bookings");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RYDMATE_API_KEY'),
'Content-Type: application/json',
// Keep this key and send it again on a retry: you get one hold, never two.
'Idempotency-Key: ' . bin2hex(random_bytes(16)),
],
CURLOPT_POSTFIELDS => json_encode([
'seat_number' => '3A',
'passenger' => ['full_name' => 'Ngozi Okafor'],
'channel' => 'PUBLIC_WEB',
]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
]);
$body = json_decode(curl_exec($ch), true);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($status === 409) {
echo 'Seat already taken: ', $body['error']['message'], PHP_EOL;
} elseif ($status >= 400) {
throw new RuntimeException($body['error']['code'] . ': ' . $body['error']['message']);
} else {
echo 'Seat held ', $body['data']['id'], PHP_EOL;
}Check that an update really came from Rydmate
Rydmate tells your system the moment a trip, ticket, delivery or payment changes. Each update is signed with your endpoint's secret. Check the signature before you act on it, and refuse anything older than five minutes.
<?php
// Checks the Rydmate-Signature header on a webhook delivery.
// $rawBody must be the request body exactly as it arrived: file_get_contents('php://input').
function verifyRydmateSignature(string $secret, string $header, string $rawBody, int $tolerance = 300): bool
{
$parts = [];
foreach (explode(',', $header) as $part) {
[$key, $value] = array_pad(explode('=', trim($part), 2), 2, '');
$parts[$key] = $value;
}
$t = $parts['t'] ?? '';
$v1 = $parts['v1'] ?? '';
if (!ctype_digit($t) || $v1 === '' || abs(time() - (int) $t) > $tolerance) {
return false;
}
$expected = hash_hmac('sha256', "$t.$rawBody", $secret);
return hash_equals($expected, $v1);
}Build on Rydmate
Connect your product to real transport operations
Start on a test account, then go live when your integration is ready. Book a demo to talk through what you are building.