Skip to content

API : Pin webhooks to a specific API version - #25209

Open
f2cmb wants to merge 1 commit into
glpi-project:mainfrom
f2cmb:enhance/webhook-pinned-api-version
Open

API : Pin webhooks to a specific API version#25209
f2cmb wants to merge 1 commit into
glpi-project:mainfrom
f2cmb:enhance/webhook-pinned-api-version

Conversation

@f2cmb

@f2cmb f2cmb commented Aug 20, 2026

Copy link
Copy Markdown
Contributor
  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

Webhooks build their payload by calling the HL API internally, and that internal request never carried a version header, so the router always fell back to Router::API_VERSION. That is harmless while v2 is the only major, but the day v3 becomes the default, every existing webhook would start sending v3 payloads without anyone having changed anything on their side.

Each webhook now stores the API major version its payload is built against:

  • a pinned_version column and a dropdown on the webhook form
  • Webhook::getAPIResponse() sends it as the GLPI-API-Version header
  • a migration pins existing webhooks to "2", new ones default to the highest available major
  • deprecated majors are flagged in the dropdown, with a warning on the form

Only majors can be pinned, the router already resolves them to their latest minor. v1 is excluded since it is routed to the legacy API and would resolve no webhook path.

Nothing changes today: "2" resolves to 2.4.0, which is already the router default, so payloads are identical before and after. The dropdown holds a single entry until v3 ships.

Left out on purpose : the itemtype list still offers ITIL subtypes whatever the pinned version, since they are named from a static map instead of the schemas, and the Monaco suggestions endpoint does not carry the version yet. Both belong with the v3 work.

Screenshot :

image

@f2cmb
f2cmb marked this pull request as ready for review August 20, 2026 13:33
Comment thread src/Webhook.php
'table' => self::getTable(),
'field' => 'pinned_version',
'name' => __('API version'),
'massiveaction' => false, // must be one of the pinnable versions, not free text

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Massive action updates could be supported by adding a getSpecificValueToSelect method in this class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants