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-12-12 22:55:41

rocksteady
Member
Registered: 2023-07-07
Posts: 16

How to update server's position in rack?

I'm trying to update my computer's position in rack (change rack/unit). This is my request:

curl -s -L -X PATCH 'http://devglpi1z1.mydomain.net/apirest.php/computer/466' \
-H 'Content-Type: application/json' \
-H 'App-Token: 7Ja9hnKdzABCL7qAi1CSwyDCDarb2gFGqgZfLVL' \
-H 'Session-Token: 8c0d0346bf9a0db3569c23b59cbe62d' \
-d '{
    "input": {
        "180": "6H8070",
        "181": 12
    }
}'

It says:

[
    {
        "466": true,
        "message": ""
    }
]

But nothing happens, and computer's position is not updated. What is wrong?

Offline

#2 2024-12-13 12:42:27

rocksteady
Member
Registered: 2023-07-07
Posts: 16

Re: How to update server's position in rack?

Search options:

 "180": {
        "name": "Name",
        "table": "glpi_racks",
        "field": "name",
        "datatype": "dropdown",
        "nosearch": false,
        "nodisplay": false,
        "available_searchtypes": [
            "contains",
            "notcontains",
            "equals",
            "notequals"
        ],
        "uid": "Computer.Item_Rack.Rack.name"
    },
    "181": {
        "name": "Position",
        "table": "glpi_items_racks",
        "field": "position",
        "datatype": "number",
        "nosearch": false,
        "nodisplay": false,
        "available_searchtypes": [
            "contains",
            "notcontains"
        ],
        "uid": "Computer.Item_Rack.position"
    },

I'm not quite understand what json payload should I send to glpi api to update these fields...

Offline

#3 2024-12-13 13:04:08

rocksteady
Member
Registered: 2023-07-07
Posts: 16

Re: How to update server's position in rack?

{
    "input": {
        "id": 466,
        "otherserial": "SRV348432",
        "Item_Rack.Rack.name": "6H8J070",
        "Item_Rack.position": 12
    }
}

This payload does not work also. It changes only 'otherserial' field.

Offline

#4 2024-12-13 14:15:29

cconard96
Moderator
Registered: 2018-07-31
Posts: 3,226
Website

Re: How to update server's position in rack?

Updates are not done with search options. If you want to update Item_Rack data, you need to do that for the Item_Rack resource, not the computer.

PATCH 'apirest.php/Item_Rack/ITEM_RACK_ID'
{
    "input": {
        "id": ITEM_RACK_ID,
        "position": 12
    }
}


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

#5 2024-12-13 14:44:30

rocksteady
Member
Registered: 2023-07-07
Posts: 16

Re: How to update server's position in rack?

Thanks. This works for servers in racks. But how do I get item_id for servers, that are not in racks yet? I have a bunch of servers that I need to put into racks, how do I do it?

P.S. Is there any document that describe how to work with racks via api?

Last edited by rocksteady (2024-12-13 14:54:57)

Offline

#6 2024-12-13 15:22:35

rocksteady
Member
Registered: 2023-07-07
Posts: 16

Re: How to update server's position in rack?

I need to do something like this:

curl -s -L -X PUT 'http://devglpi1z1.mydomain.net/apirest.php/rack/Item_Rack?get_hateoas=false' \
-H 'Content-Type: application/json' \
-H 'App-Token: 7Ja9hnKdzABCL7qAi1CNSwyDCDarb2gFGqgZfLVL' \
-H 'Session-Token: c11cec4e0aeaf067b445e1db3c8782cf' \
-d '{
    "input": {
        "id": 93, #Rack ID
        "items_id": 466, #Computer ID
        "position": 40,
        "orientation": 0,
        "bgcolor": "#69ceba",
        "hpos": 0,
        "is_reserved": 0
    }
}'

But it doesn't work...

Last edited by rocksteady (2024-12-13 15:30:38)

Offline

Board footer

Powered by FluxBB