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-02-08 18:50:53

Grouic
Member
Registered: 2024-02-08
Posts: 2

Api Add_Item avec body dans une variable Shell

Bonjour,

j'essaye dans un programme bash d'appeler l'api add_item pour créer un computer.
Le body est dans une variable $INPUT_DATA_ITEM qui contient {"input":[{"name":"PC_TEST_ALAIN","serial":"ABCDE10002"}]}

curl -X POST \
                -H "Content-Type: application/json" \
                -H "Session-Token: $GLPI_TOKEN" \
                -H "App-Token: $GLPI_APP_TOKEN" \
                -d "$INPUT_DATA_ITEM" \
                -s 'http://'"$GLPI_SERVER"'/glpi/apirest.php/computer'

En mettant le contenu de la variable, ca fonctionne bien, mais en mettant le $INPUT_DATA_ITEM, j'ai un ["ERROR_BAD_ARRAY","Le paramètre input doit être un tableau d'objets ...

Je pense que cela vient de la manière dont je dois passer ma variable dans le curl, mais je ne trouve pas (avec des ', des ", des "'", etc ...)

Je suis preneur de toute idée ou suggestion !

Merci pour votre aide.

Grouic

Offline

#2 2024-02-08 23:01:50

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,435
Website

Re: Api Add_Item avec body dans une variable Shell

I think:
{"input":[{"name":"PC_TEST_ALAIN","serial":"ABCDE10002"}]}
Should be replaced with:
{"input":{"name":"PC_TEST_ALAIN","serial":"ABCDE10002"}}


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#3 2024-02-09 10:51:31

Grouic
Member
Registered: 2024-02-08
Posts: 2

Re: Api Add_Item avec body dans une variable Shell

Hello,

I put the [] because I may need to add multiple computers in 1 api call (then the input needs an array).

I tried without the [] and doesn't work neither.

Still thx for the help big_smile

Offline

#4 2024-02-09 10:58:01

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

Re: Api Add_Item avec body dans une variable Shell

endpoint are  case sensitive
http://'"$GLPI_SERVER"'/glpi/apirest.php/Computer'


Trouver la panne avant de réparer...
GLPI10.0.10 (ubuntu 22.04 PHP8.1  Mariadb10.6 ) plugins : comportements 2.7.2 reports 1.16.0 formcreator 2.13.8, datainjection 2.13.4 fields 1.21.6
préprod : glpi10.0.15

Offline

Board footer

Powered by FluxBB