klikresi / php-sdk
Official PHP SDK for the Klik Resi API: shipment tracking, shipping rates, and Indonesian location lookup.
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^7.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0 || ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- php-http/mock-client: ^1.6
- phpunit/phpunit: ^10.5 || ^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Official PHP client for the Klik Resi API. Track shipments, calculate shipping rates, and look up Indonesian locations (provinces, cities, districts) across couriers such as JNE, J&T, Shopee Express, SiCepat, TIKI, and more.
Full API reference: docs.klikresi.com
Requirements
- PHP 8.1+
- A PSR-18 HTTP client (Guzzle 7 is installed by default)
Installation
composer require klikresi/php-sdk
Quickstart
<?php require 'vendor/autoload.php'; use Klikresi\PhpSdk\Client; use Klikresi\PhpSdk\Courier; $client = new Client('YOUR-API-KEY'); $tracking = $client->tracking()->get('YOUR-AWB', Courier::JNE); echo $tracking->status.PHP_EOL; foreach ($tracking->histories as $history) { echo $history->date->format('Y-m-d H:i').' '.$history->message.PHP_EOL; }
Usage
Tracking
// Basic tracking (charged per successful request). $t = $client->tracking()->get('YOUR-AWB', Courier::JNE); // ID Express requires an extra `number` (phone number) parameter. // When provided, it is passed through as a query parameter. $t = $client->tracking()->get('YOUR-AWB', Courier::ID_EXPRESS, ['number' => '08123456789']);
The response contains a normalized status
(DeliveryStatus::INFO_RECEIVED, IN_TRANSIT, OUT_FOR_DELIVERY,
FAILED_ATTEMPT, DELIVERED, RETURN_TO_SENDER, EXCEPTION, EXPIRED,
PENDING) plus origin, destination, and the full event history
(dates as DateTimeImmutable).
Rates
// By district IDs, optionally filtered to specific couriers. $r = $client->rates()->calculateById('33.08.20', '32.09.31', 1, [Courier::JNE]); // By location names. $r = $client->rates()->calculateByName('Secang, Kabupaten Magelang, Jawa Tengah', 'Depok, Kabupaten Cirebon, Jawa Barat', 1); // By postal codes. $r = $client->rates()->calculateByPostalCode(56195, 45155, 1);
Location
All location endpoints are cursor-paginated. Request one page, or use the
all* helpers to fetch everything automatically.
// Search locations by keyword. $page = $client->location()->search('depok', ['limit' => 10]); echo $page->nextCursor.PHP_EOL; // Single pages. $provinces = $client->location()->provinces(); $cities = $client->location()->cities('33'); $districts = $client->location()->districts('33.08'); // Everything, following cursors automatically. $all = $client->location()->allLocations('depok'); $allProvinces = $client->location()->allProvinces();
Me
// Fetch the profile of the account that owns the API key. $me = $client->me()->get();
The response contains the account id, name, email, and current balance.
Courier codes
Use the Courier constants: Courier::SPX, Courier::JNE, Courier::JNT,
Courier::SICEPAT, Courier::NINJA, Courier::POS, Courier::SAP,
Courier::LEX, Courier::LION, Courier::ID_EXPRESS, Courier::ANTERAJA,
Courier::WAHANA, Courier::TIKI.
Errors
Any non-2xx response throws a Klikresi\PhpSdk\Exceptions\ApiException
carrying the HTTP status and the API's message:
use Klikresi\PhpSdk\Exceptions\ApiException; try { $client->tracking()->get('YOUR-AWB', Courier::JNE); } catch (ApiException $e) { echo $e->getStatusCode().' '.$e->getMessage().PHP_EOL; }
Configuration
The client constructor takes only your API key. The base URL defaults to
https://klikresi.com; it can be overridden with the KLIKRESI_BASE_URL
environment variable (useful for tests and proxies). Requests time out
after 30 seconds.
The client is built on PSR-18 and PSR-17: Guzzle 7 is used by default, and
you can plug in any other implementation by overriding the internal
createHttp() factory in a subclass.
Examples
See the examples directory for runnable samples.
License
MIT