Ready-to-use SDK wrapper code for PHP, JavaScript, and Python. Copy-paste into your project.
<?php
/**
* UETDS Pro API PHP SDK
*
* Usage:
* $client = new UetdsApiClient('sk_live_xxx');
* $journeys = $client->listJourneys();
* $journey = $client->createJourney([...]);
*/
class UetdsApiClient {
private string $apiKey;
private string $baseUrl;
public function __construct(string $apiKey, string $baseUrl = '<?= htmlspecialchars(API_BASE_URL) ?>') {
$this->apiKey = $apiKey;
$this->baseUrl = rtrim($baseUrl, '/');
}
private function request(string $method, string $path, array $data = null): array {
$url = $this->baseUrl . '/' . ltrim($path, '/');
$ch = curl_init($url);
$headers = [
'Authorization: Bearer ' . $this->apiKey,
'Content-Type: application/json'
];
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers
]);
if ($data && in_array($method, ['POST', 'PUT', 'PATCH'])) {
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
}
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($response, true);
if ($httpCode >= 400) {
throw new Exception($result['error'] ?? 'API Error', $httpCode);
}
return $result;
}
// Journeys
public function listJourneys(): array {
return $this->request('GET', '/portal/journeys');
}
public function getJourney(int $id): array {
return $this->request('GET', "/portal/journeys/{$id}");
}
public function createJourney(array $data): array {
return $this->request('POST', '/portal/journeys', $data);
}
public function updateJourney(int $id, array $data): array {
return $this->request('PUT', "/portal/journeys/{$id}", $data);
}
public function deleteJourney(int $id): array {
return $this->request('DELETE', "/portal/journeys/{$id}");
}
public function submitJourney(int $id): array {
return $this->request('POST', "/portal/journeys/{$id}/submit");
}
// Passengers
public function listPassengers(int $journeyId): array {
return $this->request('GET', "/portal/journeys/{$journeyId}/passengers");
}
public function addPassenger(int $journeyId, array $data): array {
return $this->request('POST', "/portal/journeys/{$journeyId}/passengers", $data);
}
public function updatePassenger(int $journeyId, int $passengerId, array $data): array {
return $this->request('PUT', "/portal/journeys/{$journeyId}/passengers/{$passengerId}", $data);
}
public function deletePassenger(int $journeyId, int $passengerId): array {
return $this->request('DELETE', "/portal/journeys/{$journeyId}/passengers/{$passengerId}");
}
// Vehicles
public function listVehicles(): array {
return $this->request('GET', '/portal/vehicles');
}
public function createVehicle(array $data): array {
return $this->request('POST', '/portal/vehicles', $data);
}
public function updateVehicle(int $id, array $data): array {
return $this->request('PUT', "/portal/vehicles/{$id}", $data);
}
public function deleteVehicle(int $id): array {
return $this->request('DELETE', "/portal/vehicles/{$id}");
}
// Personnel
public function listPersonnel(): array {
return $this->request('GET', '/portal/personnel');
}
public function createPersonnel(array $data): array {
return $this->request('POST', '/portal/personnel', $data);
}
// Cargo
public function listCargo(): array {
return $this->request('GET', '/portal/cargo');
}
public function createCargo(array $data): array {
return $this->request('POST', '/portal/cargo', $data);
}
public function submitCargo(int $id): array {
return $this->request('POST', "/portal/cargo/{$id}/submit");
}
// Submissions
public function listSubmissions(): array {
return $this->request('GET', '/portal/submissions');
}
public function getSubmission(int $id): array {
return $this->request('GET', "/portal/submissions/{$id}");
}
// Webhooks
public function listWebhooks(): array {
return $this->request('GET', '/portal/webhooks');
}
public function createWebhook(array $data): array {
return $this->request('POST', '/portal/webhooks', $data);
}
// Reference Data
public function listCities(): array {
return $this->request('GET', '/ref/cities');
}
public function listDistricts(int $cityId): array {
return $this->request('GET', "/ref/districts?city_id={$cityId}");
}
}
/**
* UETDS Pro API JavaScript SDK
*
* Usage:
* import { UetdsClient } from './uetds-client.js';
* const client = new UetdsClient('sk_live_xxx');
* const journeys = await client.listJourneys();
*/
export class UetdsClient {
constructor(apiKey, baseUrl = '<?= htmlspecialchars(API_BASE_URL) ?>') {
this.apiKey = apiKey;
this.baseUrl = baseUrl.replace(/\/$/, '');
}
async request(method, path, data = null) {
const url = `${this.baseUrl}/${path.replace(/^\//, '')}`;
const options = {
method,
headers: {
'Authorization': `Bearer ${this.apiKey}`,
'Content-Type': 'application/json'
}
};
if (data && ['POST', 'PUT', 'PATCH'].includes(method)) {
options.body = JSON.stringify(data);
}
const response = await fetch(url, options);
const result = await response.json();
if (!response.ok) {
throw new Error(result.error || 'API Error');
}
return result;
}
// Journeys
async listJourneys() {
return this.request('GET', '/portal/journeys');
}
async getJourney(id) {
return this.request('GET', `/portal/journeys/${id}`);
}
async createJourney(data) {
return this.request('POST', '/portal/journeys', data);
}
async updateJourney(id, data) {
return this.request('PUT', `/portal/journeys/${id}`, data);
}
async deleteJourney(id) {
return this.request('DELETE', `/portal/journeys/${id}`);
}
async submitJourney(id) {
return this.request('POST', `/portal/journeys/${id}/submit`);
}
// Passengers
async listPassengers(journeyId) {
return this.request('GET', `/portal/journeys/${journeyId}/passengers`);
}
async addPassenger(journeyId, data) {
return this.request('POST', `/portal/journeys/${journeyId}/passengers`, data);
}
async updatePassenger(journeyId, passengerId, data) {
return this.request('PUT', `/portal/journeys/${journeyId}/passengers/${passengerId}`, data);
}
async deletePassenger(journeyId, passengerId) {
return this.request('DELETE', `/portal/journeys/${journeyId}/passengers/${passengerId}`);
}
// Vehicles
async listVehicles() {
return this.request('GET', '/portal/vehicles');
}
async createVehicle(data) {
return this.request('POST', '/portal/vehicles', data);
}
async updateVehicle(id, data) {
return this.request('PUT', `/portal/vehicles/${id}`, data);
}
async deleteVehicle(id) {
return this.request('DELETE', `/portal/vehicles/${id}`);
}
// Personnel
async listPersonnel() {
return this.request('GET', '/portal/personnel');
}
async createPersonnel(data) {
return this.request('POST', '/portal/personnel', data);
}
// Cargo
async listCargo() {
return this.request('GET', '/portal/cargo');
}
async createCargo(data) {
return this.request('POST', '/portal/cargo', data);
}
async submitCargo(id) {
return this.request('POST', `/portal/cargo/${id}/submit`);
}
// Submissions
async listSubmissions() {
return this.request('GET', '/portal/submissions');
}
async getSubmission(id) {
return this.request('GET', `/portal/submissions/${id}`);
}
// Webhooks
async listWebhooks() {
return this.request('GET', '/portal/webhooks');
}
async createWebhook(data) {
return this.request('POST', '/portal/webhooks', data);
}
// Reference Data
async listCities() {
return this.request('GET', '/ref/cities');
}
async listDistricts(cityId) {
return this.request('GET', `/ref/districts?city_id=${cityId}`);
}
}
"""
UETDS Pro API Python SDK
Usage:
from uetds_client import UetdsClient
client = UetdsClient('sk_live_xxx')
journeys = client.list_journeys()
journey = client.create_journey({...})
"""
import requests
from typing import Optional, Dict, Any, List
class UetdsClient:
def __init__(self, api_key: str, base_url: str = '<?= htmlspecialchars(API_BASE_URL) ?>'):
self.api_key = api_key
self.base_url = base_url.rstrip('/')
self.session = requests.Session()
self.session.headers.update({
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
})
def _request(self, method: str, path: str, data: Optional[Dict] = None) -> Dict[str, Any]:
url = f"{self.base_url}/{path.lstrip('/')}"
response = self.session.request(method, url, json=data)
response.raise_for_status()
return response.json()
# Journeys
def list_journeys(self) -> Dict[str, Any]:
return self._request('GET', '/portal/journeys')
def get_journey(self, journey_id: int) -> Dict[str, Any]:
return self._request('GET', f'/portal/journeys/{journey_id}')
def create_journey(self, data: Dict[str, Any]) -> Dict[str, Any]:
return self._request('POST', '/portal/journeys', data)
def update_journey(self, journey_id: int, data: Dict[str, Any]) -> Dict[str, Any]:
return self._request('PUT', f'/portal/journeys/{journey_id}', data)
def delete_journey(self, journey_id: int) -> Dict[str, Any]:
return self._request('DELETE', f'/portal/journeys/{journey_id}')
def submit_journey(self, journey_id: int) -> Dict[str, Any]:
return self._request('POST', f'/portal/journeys/{journey_id}/submit')
# Passengers
def list_passengers(self, journey_id: int) -> Dict[str, Any]:
return self._request('GET', f'/portal/journeys/{journey_id}/passengers')
def add_passenger(self, journey_id: int, data: Dict[str, Any]) -> Dict[str, Any]:
return self._request('POST', f'/portal/journeys/{journey_id}/passengers', data)
def update_passenger(self, journey_id: int, passenger_id: int, data: Dict[str, Any]) -> Dict[str, Any]:
return self._request('PUT', f'/portal/journeys/{journey_id}/passengers/{passenger_id}', data)
def delete_passenger(self, journey_id: int, passenger_id: int) -> Dict[str, Any]:
return self._request('DELETE', f'/portal/journeys/{journey_id}/passengers/{passenger_id}')
# Vehicles
def list_vehicles(self) -> Dict[str, Any]:
return self._request('GET', '/portal/vehicles')
def create_vehicle(self, data: Dict[str, Any]) -> Dict[str, Any]:
return self._request('POST', '/portal/vehicles', data)
def update_vehicle(self, vehicle_id: int, data: Dict[str, Any]) -> Dict[str, Any]:
return self._request('PUT', f'/portal/vehicles/{vehicle_id}', data)
def delete_vehicle(self, vehicle_id: int) -> Dict[str, Any]:
return self._request('DELETE', f'/portal/vehicles/{vehicle_id}')
# Personnel
def list_personnel(self) -> Dict[str, Any]:
return self._request('GET', '/portal/personnel')
def create_personnel(self, data: Dict[str, Any]) -> Dict[str, Any]:
return self._request('POST', '/portal/personnel', data)
# Cargo
def list_cargo(self) -> Dict[str, Any]:
return self._request('GET', '/portal/cargo')
def create_cargo(self, data: Dict[str, Any]) -> Dict[str, Any]:
return self._request('POST', '/portal/cargo', data)
def submit_cargo(self, cargo_id: int) -> Dict[str, Any]:
return self._request('POST', f'/portal/cargo/{cargo_id}/submit')
# Submissions
def list_submissions(self) -> Dict[str, Any]:
return self._request('GET', '/portal/submissions')
def get_submission(self, submission_id: int) -> Dict[str, Any]:
return self._request('GET', f'/portal/submissions/{submission_id}')
# Webhooks
def list_webhooks(self) -> Dict[str, Any]:
return self._request('GET', '/portal/webhooks')
def create_webhook(self, data: Dict[str, Any]) -> Dict[str, Any]:
return self._request('POST', '/portal/webhooks', data)
# Reference Data
def list_cities(self) -> Dict[str, Any]:
return self._request('GET', '/ref/cities')
def list_districts(self, city_id: int) -> Dict[str, Any]:
return self._request('GET', f'/ref/districts?city_id={city_id}')