Skip to content

PHP API, Hooks & CLI

Resolve Headless via ProcessWire\Headless::requireInstance($wire) (or $this->wire()->modules->get('Headless')).

Group Key Methods
Mode & Routing doHeadless(), isFullHeadless(), apiPrefix(), passthroughMatcher(), shouldPassThrough(), configure()
Registration batchRegistration(), expose(), action(), registerScope(), registerScopes(), getAvailableScopes(), registerWebhookEvent(), registerWebhookEvents(), getAvailableWebhookEvents(), registerProvider(), registerTransformer(), registerGuard(), discoverProviderModules(), ensureProvidersPulled()
Auth & Security issueJwtToken(), issuePreviewToken(), verifyPreviewToken(), verifyPreviewRequest(), verifyAccess(), ensurePersistentSecret(), secretFor(), withInternalCredentialWrite(), prepareHeadlessItemForSave(), cloneHeadlessItem()
Serialization & Dispatch serialize(), resolveLanguageByKey(), pageAccessPolicy(), pageSerializer(), pagePaginator(), schemaProvider(), buildOpenApiSchema(), handle(), createRequestFromEnvironment()
Storage & Webhooks keys(), tokens(), webhooks(), webhookDispatcher(), settings(), saveSettings(), clearCache()
Hook Arguments & Return Timing What It Does
Headless::registerProviders (): void After Invoked during ready() and resetState() so site code or modules register ResourceBlueprints, HeadlessActions, HeadlessProviderInterfaces, FieldTransformerInterfaces, scopes, and webhook events.
Headless::clearCache (): void After Fires when Headless API and provider caches are flushed via the Overview UI or $headless->clearCache().
ProcessHeadless::translations (): array After Returns the localized UI string map for the Setup -> Headless React workspace.

Register a Custom REST Provider & React to Cache Flushes

Section titled “Register a Custom REST Provider & React to Cache Flushes”
site/ready.php
<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Headless\Blueprint\ResourceBlueprint;
$wire->addHookAfter('Headless::registerProviders', function (HookEvent $event): void {
/** @var Headless $headless */
$headless = $event->object;
$headless->expose(
ResourceBlueprint::forTemplate('yacht')
->fields(['title', 'summary', 'cabins', 'weekly_rate'])
->publicRead()
);
});
$wire->addHookAfter('Headless::clearCache', function (HookEvent $event): void {
$event->wire()->log->save('headless', 'Headless API schema and route caches were flushed.');
});

All 4 CLI Commands & Flags (vendor/bin/wire)

Section titled “All 4 CLI Commands & Flags (vendor/bin/wire)”

Creates a scoped whk_* Personal Access Token bound to a ProcessWire user:

Terminal window
php vendor/bin/wire headless:key:create "Aegean Frontend Storefront" \
--scopes=pages:read,entries:read \
--user=api-bot \
--rate-limit=240 \
--dry-run \
--json

Flags: --scopes, --user, --rate-limit, --dry-run, --json.

Lists all active and expired headless-keys records with prefixes, bound users, scopes, and last-used timestamps:

Terminal window
php vendor/bin/wire headless:key:list --json

Flags: --json.

Inspects all registered REST providers, resources, actions, and URL prefixes:

Terminal window
php vendor/bin/wire headless:routes --public --json

Flags: --public, --json.

Deletes expired and revoked whr_* refresh tokens from headless-tokens:

Terminal window
php vendor/bin/wire headless:token:prune --dry-run --force --json

Flags: --dry-run, --force, --json.

Background Queue (DeliverHeadlessWebhookQueue) & Webhook Verification

Section titled “Background Queue (DeliverHeadlessWebhookQueue) & Webhook Verification”

ProcessWire\DeliverHeadlessWebhookQueue (queue/DeliverHeadlessWebhookQueue.php) invokes WebhookDispatcher::deliverQueued($payload) for asynchronous webhook dispatch (webhook_id, event, timestamp, data). Run php vendor/bin/wire queue:work --tries=3 --sleep=3 in production so queued webhook deliveries process automatically.

Every outbound webhook includes X-Headless-Event, X-Headless-Timestamp, X-Headless-Nonce, and X-Headless-Signature (sha256=<hex>):

{
"event": "entries.saved",
"timestamp": "2026-06-15T13:15:00Z",
"data": {
"type": "charter-yachts",
"id": "0196f8d2-3c1a-7b40-9e12-8a4c5d6e7f01"
}
}
<?php
declare(strict_types=1);
$rawBody = file_get_contents('php://input') ?: '';
$timestamp = $_SERVER['HTTP_X_HEADLESS_TIMESTAMP'] ?? '';
$received = $_SERVER['HTTP_X_HEADLESS_SIGNATURE'] ?? '';
$expected = 'sha256=' . hash_hmac('sha256', $timestamp . '.' . $rawBody, (string) getenv('HEADLESS_WEBHOOK_SECRET'));
$isValid = hash_equals($expected, $received);

401 Unauthorized With Authorization: Bearer on Apache/FastCGI

Section titled “401 Unauthorized With Authorization: Bearer on Apache/FastCGI”

Symptom: Valid whk_* or JWT tokens are ignored by the API.

Fix: Ensure your web server forwards the Authorization header to PHP (RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] on Apache), or pass X-Api-Key: whk_... for API keys.

Frontend Sitemaps or Custom URL Hooks Return JSON in Full Headless Mode

Section titled “Frontend Sitemaps or Custom URL Hooks Return JSON in Full Headless Mode”

Symptom: /sitemap.xml or a custom module endpoint is intercepted by Full Headless mode.

Fix: Add the path pattern to Settings -> Passthrough Paths (or $headless->doHeadless(..., passthroughPaths: [...])).

403 Forbidden Updating Settings or Issuing full_access Keys

Section titled “403 Forbidden Updating Settings or Issuing full_access Keys”

Symptom: A user with the headless permission cannot modify global Settings or create full_access keys.

Fix: Global headless Settings writes, full_access keys, and cross-user key assignment are intentionally restricted to superuser accounts (and blocked when $config->demo is active).

Next steps