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-03-22 14:37:44

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

How to update computer's manufacturer and model using glpi api?

Hey, guys. I'm trying to synchronize NetBox (new discovered servers appears first here) and GLPI using python module glpi_api.
When I'm trying to update computer like this:

parameters = {
  'id': glpi_id, 
  'name': netbox_name, 
  'Manufacturer.name': netbox_manufacturer, 
  'ComputerModel.name': device_type, 
  'otherserial': netbox_inventory
}
glpi.update('Computer', parameters)

I'm getting response:

Error processing device with serial number : Object of type DeviceTypes is not JSON serializable

What am I doing wrong?

Offline

#2 2024-03-22 16:56:36

At0kir
Member
Registered: 2024-03-22
Posts: 2

Re: How to update computer's manufacturer and model using glpi api?

Seems like the data from netbox_inventory is not in a JSON format. You will have to JSON serialize it. Here is an example:


# import module
import json

# Data to be written
parameters = {
  'id': glpi_id,
  'name': netbox_name,
  'Manufacturer.name': netbox_manufacturer,
  'ComputerModel.name': device_type,
  'otherserial': netbox_inventory
}

# Serializing json
res = json.dumps( parameters )
glpi.update('Computer', res)

You have to use json.dumps to convert it to JSON type.

Last edited by At0kir (2024-03-22 17:20:43)

Offline

#3 2024-03-22 17:32:21

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

Re: How to update computer's manufacturer and model using glpi api?

Well, it is in json format.. if we print(parameters):

{'id': 2125, 'name': '3c:e1:a1:83:91:9b', 'Manufacturer.name': 'Lenovo', 'ComputerModel.name': HR650X, 'otherserial': 'SRV371753'}

upd: Ok, I got it. 'ComputerModel.name' - value should be string like this: 'ComputerModel.name': 'HR650X'. Solved)

Last edited by rocksteady (2024-03-22 19:18:39)

Offline

Board footer

Powered by FluxBB