You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2023-06-01 13:19:34

no_username
Member
Registered: 2023-06-01
Posts: 2

Add or Update field generated by fieldsPlugin with API request

Hi, I have been trying to update/create some values of a form (a tab in Ticket Entity)  generated by fieldsPlugin but the values won't change.

Note that ${} represents a ficticious value.

I'm doing this type of request:

curl -X PUT -H 'Content-Type: application/json' -H "Session-Token: ${$mySessionToken}" -H "App-Token: ${myAppToken}" -d '{"input": {"PluginFieldsTicket${TabName}": {"${name}field": "Bla", "${number}field": "1"}}}' 'http://${serverName}/apirest.php/Ticket/${ticketId}/'

and  it returns:

[{"${ticketId}":true,"message":""}]

however the field's values are not being updated, am I doing anything wrong?
If so, please give me any sugestion!

Offline

#2 2023-06-01 16:47:08

no_username
Member
Registered: 2023-06-01
Posts: 2

Re: Add or Update field generated by fieldsPlugin with API request

The problem has been solved!

Note that ${} represents a ficticious value and $[] represents any mandatory data to your plugin entity generation.

In order to make a Post request to your custom form you should do this:

curl -X POST -H 'Content-Type: application/json' -H "Session-Token: ${$mySessionToken}" -H "App-Token: ${myAppToken}" -d '{"input": $[{"${fakeMandatoryKey1}": "${fakeMandatoryValue1}", ...], "plugin_fields_containers_id": "${containerId}", "items_id": "${ticketId}"}}' 'http://${serverName}/apirest.php/PluginFieldsTicket${TabName}'

and you'll get this:

{"id":${pluginFieldTicketId},"message":"Item successfully added: General - ID ${pluginFieldTicketId} (${pluginFieldTicketId})"}

the same applyies to your Put request, you just need to add the pluginFieldTicketId to the URL just like a base Entity:

curl -X PUT -H 'Content-Type: application/json' -H "Session-Token: ${$mySessionToken}" -H "App-Token: ${myAppToken}" -d '{"input": $[{"${fakeMandatoryKey1}": "${fakeMandatoryValue1}", ...], "plugin_fields_containers_id": "${containerId}", "items_id": "${ticketId}"}}' 'http://${serverName}/apirest.php/PluginFieldsTicket${TabName}/${pluginFieldTicketId}'

you'll get something like this:

[{"${pluginFieldTicketId}":true,"message":""}]

Offline

Board footer

Powered by FluxBB