Conversation
Rom1-B
left a comment
There was a problem hiding this comment.
Please add "Using the Fields Plugin via GLPI REST API" to a new *.md file.
Reference ContextDocumentation ScopePlugin Concerned VersionFields 1.23.3 GLPI 11 DocumentationUsing the Fields Plugin via GLPI REST APITable of Contents
OverviewThe Fields plugin allows custom fields to be created and updated via the GLPI REST API. Custom fields are passed directly alongside native GLPI fields in the Minimum versions required:
PrerequisitesBefore making API calls, ensure:
AuthenticationInit Session with credentialscurl -X GET \
'https://glpi.example.com/apirest.php/initSession' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic BASE64_LOGIN_PASSWORD' \
-H 'App-Token: YOUR_APP_TOKEN'Init Session with user tokencurl -X GET \
'https://glpi.example.com/apirest.php/initSession' \
-H 'Content-Type: application/json' \
-H 'Authorization: user_token YOUR_USER_TOKEN' \
-H 'App-Token: YOUR_APP_TOKEN'Response{
"session_token": "abc123def456"
}
Understanding Field NamingWhen a field is created in the Fields plugin, its internal name (used as the API key) is derived from the label:
Examples:
The exact key to use depends on the field type — see Field Types Reference.
Container Types & TargetingThe Fields plugin supports three container types:
Auto-detection (recommended for
|
|
Hi, I'm using the cloud version of GLPI.ro, but the examples provided in @RomainLvr's documentation seem to refer to the on-premise version of GLPI. I'm unable to assign values to my custom fields because I don't know how to set them up in my version of GLPI. Thanks for you help |
|
The documentation does not differ between the cloud and on-premises versions. |
|
I have good knowledge of PHP objects, as well as MySQL tables and columns. But when using cloud instance of GLPI, one has no access to PHP objects. More, the API URL is not https://glpi.example.com/apirest.php/ but https://myinstance.glpi-network.cloud/api.php/v2.2 On my instance, the graphical interface says that my field is called dropdowns_dropdowns_id_nrtwoindicederparabilitfield I use Postman. Everything works fine when writing to native fields. But it does not work when writing to custom fields, whatever name I choose. |
|
api.php/v2.2 is for High Level API Fields is not compatible with latest API Engine You need to use /apirest.php |
|
That’s important information. Thank you for clarifying that point. I’ve enabled the ‘Enable Legacy REST API’ option. Which URL should I use? I’ve just tried https://myinstance/apirest.php/, but it didn’t work. Thanks in advance for your help |
|
I have just tried this URL: https://myinstance.glpi-network.cloud/apirest.php/initSession I have this result: Which means that API Disabled Any idea ? |
|
Yes, your legacy REST API has been deactivated. |


Checklist before requesting a review
Please delete options that are not relevant.
Description
When GLPI is booted to serve a REST API request,
plugin_init_fields()runs before the API session is established (token auth happens after boot). Because thepre_item_update,pre_item_add,item_addandpre_item_purgehooks were registered inside theSession::getLoginUserID()guard, they were never registered for API calls. As a result, any PUT/POST toTicket(or any other Fields-enabled itemtype) silently ignored all plugin field values and only persisted native GLPI fields.A secondary issue in
PluginFieldsContainer::preItem()caused the same failure: theelse { return false; }branch on the profile rights check unconditionally rejected requests that had no active profile in session (cron, API token sessions).Fix
pre_item_update,pre_item_add,item_add,pre_item_purge),ITEM_TRANSFERandplugin_fields_register_plugin_types()outside the session guard. They are now registered as soon as the plugin is active, regardless of session state. Permission checks remain enforced inside the hook callbacks.return falseon missing session profile; the check is now skipped (not failed) when no profile is active in session.Tests
ContainerItemUpdateTest.php— 4 new tests :testCrudHooksRegisteredWithoutSession— asserts hooks are registered after a session-lessplugin_init_fields()calltestUpdateTicketInApiLikeContext— full API lifecycle simulation (boot without session → restore session → update ticket with plugin fields)testCreateTicketInApiLikeContext— same for ticket creationtestUpdateTicketWithExplicitCidInApiLikeContext— same with explicitc_id