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 2024-04-16 15:22:55

wlin
Member
Registered: 2022-02-03
Posts: 7

ConsumableItems API : Assign, unassign and display

Hello,

I'm trying to assign, unassign and display consumable items used by employees. Has someone here already managed to do that ?
I cannot seem to find the right API endpoint. I can list the consumable items using /ConsumableItem and /ConsumableItem/{ConsumableItemID} but I can't get the owner of a specific Item, assign or unassign an item.
Thank you for your help.

Regards,

Offline

#2 2024-04-16 17:27:10

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 6,287

Re: ConsumableItems API : Assign, unassign and display

GLPI 10.0.14
this endpoint
https://myGLPIServer/apirest.php/ConsumableItem/1/

returns

{"date_creation":null,"date_mod":"2024-04-16 17:21:20","id":1,"entities_id":2,"is_recursive":1,
"name":"conso 1","ref":"","locations_id":0,"consumableitemtypes_id":1,
"manufacturers_id":0,"users_id_tech":4883,"groups_id_tech":0,"is_deleted":0,
"comment":"","alarm_threshold":10,"stock_target":0,"otherserial":null,
"pictures":null}}

Trouver la panne avant de réparer...
GLPI10.0.16 (ubuntu 22.04 PHP8.1  Mariadb10.6 ) plugins : comportements 2.7.3 reports 1.16.0 formcreator 2.13.9, datainjection 2.13.5 fields 1.21.9

Offline

#3 2024-04-16 17:42:06

LaDenrée
HELPER
Registered: 2012-11-19
Posts: 6,287

Re: ConsumableItems API : Assign, unassign and display

to assign an item to a tech :

method : PUT
$url="https://myGLPIServer/apirest.php/ConsumableItem/itmeID/"
$payload='{"input":{"id":1,"users_id_tech": $User_ID}}'

to assign an item to a tech :

method : PUT
$url="https://myGLPIServer/apirest.php/ConsumableItem/itmeID/"
$payload='{"input":{"id":1,"users_id_tech": 0}}'


Trouver la panne avant de réparer...
GLPI10.0.16 (ubuntu 22.04 PHP8.1  Mariadb10.6 ) plugins : comportements 2.7.3 reports 1.16.0 formcreator 2.13.9, datainjection 2.13.5 fields 1.21.9

Offline

#4 2024-04-16 18:13:56

wlin
Member
Registered: 2022-02-03
Posts: 7

Re: ConsumableItems API : Assign, unassign and display

Thank you for your reply, LaDenrée,

"https://myGLPIServer/apirest.php/ConsumableItem/1/"

does give me info about the "Modèle de consommable". However, I'm looking to assign a specific "Consomable" rather than assigning the full "Modèle de consommable" to a tech.

After some research I managed to find how to list the consumables using the following enpoint: "ConsumableItem/itemID/Consumable" which partly gives me what I was looking for:

id                 : 1431
entities_id        : 11
consumableitems_id : 29
date_in            : 2023-03-13
date_out           : 2023-04-04
itemtype           : User
items_id           : 1183
date_mod           : 2023-12-20 14:58:24
date_creation      : 2023-03-13 16:49:24
links              : {@{rel=Entity; href=https://od3i.i-tracing.lan/apirest.php/Entity/11}, @{rel=ConsumableItem; href=https://od3i.i-tracing.lan/apirest.php/ConsumableItem/29}, @{rel=User;
                     href=https://od3i.i-tracing.lan/apirest.php/User/1183}, @{rel=Infocom; href=https://od3i.i-tracing.lan/apirest.php/Consumable/1431/Infocom/

items_id corresponds to the user id to whom the consumable is assigned so now I know what consumable a specific user has.

But I still can't find how to assign or unassign a consumable. To be clear, I'm trying to do the following action from the web UI but using the API: imgur.com/a/g18PnO6

Thanks in advance

Regards,

Offline

#5 2024-04-16 18:27:47

wlin
Member
Registered: 2022-02-03
Posts: 7

Re: ConsumableItems API : Assign, unassign and display

Ok, I after some more fidgeting I managed to do what I wanted to do:

List all consumables models:

GET "ConsumableItem/"

List all consumables of a consumable model:

GET "ConsumableItem/{CONSUMABLEMODEL_ID}/Consumable?range=0-100"

Assign a consumable to a user:

$Body = '{"input": {"items_id": "652", "itemtype": "User", "date_out": "2024-04-16"}}'
PUT "ConsumableItem/{CONSUMABLEMODEL_ID}/Consumable/{CONSUMABLE_ID}")

Thank you everyone

Offline

#6 2024-04-17 10:56:27

wlin
Member
Registered: 2022-02-03
Posts: 7

Re: ConsumableItems API : Assign, unassign and display

For people looking to unassign a consumable, here is the payload:

$Body = '{"input": {"items_id": "0", "itemtype": "", "date_out": "null"}}'

The endpoint stays the same as when assigning

Regards,

Offline

Board footer

Powered by FluxBB