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-10-22 16:23:24

evobe
Member
Registered: 2023-10-22
Posts: 4

Help with updating Notepad under Computers using PowerShell

So I'm having what seems to be a common issue. Updating entries in other databases connected to the main.
Read this - Use:

curl -X POST \
-H 'Content-Type: application/json' \
-H "Session-Token xxxx" \
-H "App-Token xxxx" \
-d '{"input": {"itemtype": "Problem", "items_id": ## problem_id##, "content": "my note content"}}' \
'http://path/to/glpi/apirest.php/Notepad/'

I changed the "itemtype" to computer, added the correct computer ID and now I get a return that the note is incrementing but no note in the associated computer item.

 id message
 -- -------
7745

Can someone help with the correct syntax? Is something missing?

Last edited by evobe (2023-10-22 16:25:06)

Offline

#2 2023-10-22 16:32:44

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

Re: Help with updating Notepad under Computers using PowerShell

to update any field using API you should use PUT methode   instead of POST method.


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

Offline

#3 2023-10-23 13:41:16

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

Re: Help with updating Notepad under Computers using PowerShell

It sounds like they are trying to add a new note rather than update an existing one since they dont have an ID in the URL.


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

#4 2023-10-23 14:33:11

evobe
Member
Registered: 2023-10-22
Posts: 4

Re: Help with updating Notepad under Computers using PowerShell

Hi,
Exactly, I wanted to update a note - but I can understand because it does say 'update' Anyway, it's solved!
The return message I was getting back was actually correct, I just had to wait for the system to update.

Invoke-RestMethod -uri "$PathtoGlpi/Notepad/" -Method Post -headers $sessionheaders -Body $jsonupdate

json body - not sure if the user is required or not since when checking the profile I'm the one logged in

$updaterequest = @{input=@{
    'itemtype'="Computer"; 'items_id'="$($id)"; 'content' = "now this is a note added to GLPI from PS by me"; 'users_id' = "xxxx"
}
}

Offline

#5 2023-10-23 15:49:31

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

Re: Help with updating Notepad under Computers using PowerShell

evobe wrote:

not sure if the user is required or not since when checking the profile I'm the one logged in

It isn't. In fact, it has no effect since "users_id" is always replaced with the current user ID.


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

Board footer

Powered by FluxBB