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)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: @stable
This package is not auto-updated.
Last update: 2026-04-20 17:18:43 UTC
README
The DND and Session modules are still under development. They are currently written but not tested, although that will be remedied after I'm done writing the CPR companion app
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/foundry-api-php-client
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.0 or higher
- GuzzleHttp 7.0 or higher
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.