Rydmate API

Rydmate Go API

Connect your Go 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 Go's own tools are enough.

Go 1.24 or laterAPI reference

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_KEY in your environment. Never put the key in your code or your app.
  • No packages to install: everything here is in the Go standard library.
1

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.

main.go
package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"
)

func main() {
	api := os.Getenv("RYDMATE_API_URL")
	if api == "" {
		api = "https://api.rydmate.com/api/v1"
	}

	req, _ := http.NewRequest(http.MethodGet, api+"/vehicles", nil)
	req.Header.Set("Authorization", "Bearer "+os.Getenv("RYDMATE_API_KEY"))

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()

	var body struct {
		Data []struct {
			RegistrationNumber string `json:"registration_number"`
			Status             string `json:"status"`
		} `json:"data"`
		Error *struct {
			Code      string `json:"code"`
			Message   string `json:"message"`
			RequestID string `json:"request_id"`
		} `json:"error"`
	}
	if err := json.NewDecoder(res.Body).Decode(&body); err != nil {
		log.Fatal(err)
	}
	if body.Error != nil {
		log.Fatalf("%s: %s (%s)", body.Error.Code, body.Error.Message, body.Error.RequestID)
	}

	for _, v := range body.Data {
		fmt.Println(v.RegistrationNumber, v.Status)
	}
}

Run it with go run ..

2

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"}.

main.go
package main

import (
	"bytes"
	"crypto/rand"
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"
)

func main() {
	api := os.Getenv("RYDMATE_API_URL")
	if api == "" {
		api = "https://api.rydmate.com/api/v1"
	}

	payload, _ := json.Marshal(map[string]any{
		"seat_number": "3A",
		"passenger":   map[string]string{"full_name": "Ngozi Okafor"},
		"channel":     "PUBLIC_WEB",
	})
	req, _ := http.NewRequest(http.MethodPost, api+"/trips/"+os.Getenv("TRIP_ID")+"/bookings", bytes.NewReader(payload))
	req.Header.Set("Authorization", "Bearer "+os.Getenv("RYDMATE_API_KEY"))
	req.Header.Set("Content-Type", "application/json")
	// Keep this key and send it again on a retry: you get one hold, never two.
	req.Header.Set("Idempotency-Key", rand.Text())

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()

	var body struct {
		Data struct {
			ID string `json:"id"`
		} `json:"data"`
		Error *struct {
			Code    string `json:"code"`
			Message string `json:"message"`
		} `json:"error"`
	}
	if err := json.NewDecoder(res.Body).Decode(&body); err != nil {
		log.Fatal(err)
	}

	switch {
	case res.StatusCode == http.StatusConflict:
		fmt.Println("Seat already taken:", body.Error.Message)
	case body.Error != nil:
		log.Fatalf("%s: %s", body.Error.Code, body.Error.Message)
	default:
		fmt.Println("Seat held", body.Data.ID)
	}
}
3

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.

rydmate.go
package rydmate

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/hex"
	"strconv"
	"strings"
	"time"
)

// VerifySignature checks the Rydmate-Signature header on a webhook delivery.
// rawBody must be the request body exactly as it arrived.
func VerifySignature(secret, header string, rawBody []byte) bool {
	var t, v1 string
	for _, part := range strings.Split(header, ",") {
		k, v, _ := strings.Cut(strings.TrimSpace(part), "=")
		switch k {
		case "t":
			t = v
		case "v1":
			v1 = v
		}
	}
	unix, err := strconv.ParseInt(t, 10, 64)
	if err != nil || v1 == "" {
		return false
	}
	if age := time.Since(time.Unix(unix, 0)); age > 5*time.Minute || age < -5*time.Minute {
		return false
	}

	mac := hmac.New(sha256.New, []byte(secret))
	mac.Write([]byte(t + "."))
	mac.Write(rawBody)
	return hmac.Equal([]byte(hex.EncodeToString(mac.Sum(nil))), []byte(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.