surrealtech / threehats-api-php-wrapper
A PHP client for interacting with the Foundry VTT REST API
Package info
gitlab.com/surrealtech/threehats-api-php-wrapper
pkg:composer/surrealtech/threehats-api-php-wrapper
Requires
- php: ^8.3
- ext-openssl: *
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- jetbrains/phpstorm-attributes: ^1.3
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: @stable
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2026-10-29 10:17:45 UTC
README
Up to date with foundryvtt-rest-api-relay v3.4.1 for the endpoints listed in the Wrapper Documentation. See the Changelog for what changed.
The D&D 5e and Session (handshake) modules are unit tested but haven't been tried against a live world yet. Scenes, chat, canvas/tokens, effects, users, playlists and the SSE subscription endpoints are not wrapped yet.
Foundry VTT REST API Client
A PHP client for interacting with the ThreeHats Foundry VTT REST API. This client provides a comprehensive set of methods to interact with the Foundry VTT REST API, making it easy(?) to integrate Foundry VTT with your PHP applications.
Installation
You can install the package via composer:
composer require surrealtech/threehats-api-php-wrapper
Usage
require_once __DIR__ . '/vendor/autoload.php'; // If needed
use FoundryClient\FoundryClient;
// Initialize the client with your API key and base URL
$wrapper = new FoundryClient(
'https://foundryvtt-rest-api-relay.fly.dev',
'your-api-key'
);
// Get the API status
$status = $wrapper->getApiStatus();
//If it returns the status of "OK", congrats the wrapper is good to go.
/*
* I've included a (somewhat unnecessary and overengineered) prettyfier for any JSON output
* Most functions' last parameter will be the prettify param, false as default
* To display it correctly I've included a rip of the CSS from my project
* Either paste it into your stylesheet or use this to put it on page:
* Aside from looking nice, it replaces a whole JSON with html + enables a Copy function for most IDs and UUIDs.
* Useful for testing and messing around
*/
echo "<style>";
require_once __DIR__ . '/src/style.css';
echo "</style>";
// Get connected clients - save ID to a var or database
// Any ID will be copy&paste clickable when prettify is enabled.
$clients = $wrapper->api->getClients(true); //Bool to enable prettify
echo '<pre>'; print_r($clients); echo '</pre>'; //Include the pre tags for any return call
// Search for entities
$searchResults = $wrapper->entity->searchEntities('your-client-id', 'search-query', 'filter');
// Delete an entity
$deleteResult = $wrapper->entity->deleteEntity('your-client-id', 'entity-uuid');
// ... and many more methods for interacting with the Foundry VTT REST API
Wrapper Documentation
For detailed documentation of all available methods, including parameters, return values, and example usage, please see the Wrapper Documentation.
Requirements
- PHP 8.3 or higher
- GuzzleHttp 7.0 or higher
Testing
The test suite mocks all HTTP traffic, so it needs no relay or API key:
composer install
composer test
composer phpstan # static analysis, config in phpstan.neon
How to use Foundry REST API - Pasted from their github, please check it out!
- Install the Foundry VTT Module (https://github.com/ThreeHats/foundryvtt-rest-api)
- Get an API key for the public relay server at https://foundryvtt-rest-api-relay.fly.dev/
- Each request must have your API key in the "x-api-key" header, except for /api/status and /api/docs.
- Endpoints other than /clients require a clientId parameter that matches a connected world.
License
The MIT License (MIT). Please see License File for more information.