This is a PHP library created to simplify development using the TruckersMP API. This library provides functions to connect and gather data from each API endpoint, and returns the data as a class with getting functions.
If you want to use the API without a library (or if you have advanced knowledge of PHP), check out our API documentation.
Please use our service responsibly. People who make lots of requests to our API should contact TruckersMP Staff with a rationale and contact email.
- PHP 7.1.0 or newer
- Composer
This library can be installed using Composer.
Two ways:
- Execute command
composer require truckersmp/api-client
- Add
truckersmp/api-client
manually to the composer requirements list.
After doing either of the above, execute the command composer install
.
Please note: this example doesn't use caching. You should cache your requests in order to use API responsibly. Some examples can be found in
examples\cache
folder.
<?php
use TruckersMP\Client;
$client = new Client();
// Get player data for player id 50
$player = $client->player(50);
// Get player data for player with SteamID 76561197965863564
$player = $client->player(76561197965863564);
// output the user's name
echo $player->getName();
// output the user's group
echo $player->getGroupName();
All timestamps in this project return a Carbon class.
player(int $id): PlayerModel
- Get player info by either TruckersMP ID or Steam IDbans(int $id): BansModel
- Get bans for a player by player IDservers(): ServersModel
- Get a list of serversgameTime(): GameTimeModel
- Get the server timeversion(): VersionModel
- DEPRECATED Get the TruckersMP version inforules(): RulesModel
- Get the TruckersMP rules
getExpires(): ?Carbon
getCreated(): Carbon
isActive(): bool
getReason(): string
getAdminName(): string
getAdminID(): int
Contains an array of BanModels.
getTime(): Carbon
getId(): int
getName(): string
getAvatar(): string
getJoinDate(): Carbon
getSteamID64(): string
getGroupID(): int
getGroupName(): string
isAdmin(): bool
getRules(): string
getRevision(): int
getId(): int
getGame(): string
getIp(): string
getPort(): int
getName(): string
getShortName(): string
isOnline(): bool
getPlayers(): int
getQueue(): int
getMaxPlayers(): int
hasSpeedLimit(): bool
hasCollisions(): bool
canPlayersHaveCars(): bool
canPlayersHavePoliceCars(): bool
isAfkEnabled(): bool
hasSyncDelay(): bool
Contains an array of ServerModels.
getVersion(): stdClass
getChecksum(): stdClass
getReleased(): Carbon
getSupport(): stdClass
We use Guzzle to get data from an API endpoint. If you want to change the Guzzle configuration then you can pass config array during Client intialization.
You can also pass a second parameter to specify HTTP
(false) or HTTPS
(true) requests. This is true by default.
<?php
$shouldUseHTTPS = true;
$client = new APIClient([
// Guzzle config
], $shouldUseHTTPS);
All other settings you can find in APIClient.php
constructor.
If you have any questions about library usage, you can create a new issue or make a topic on our forum.