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 2021-11-05 17:11:57

Drumhazzard
Member
Registered: 2011-09-19
Posts: 47

Python API - Document_Item add Issues

Hi all!

I hope all of you are fine

I'm working in some python functions for my glpi integrations. I can upload a document without issue, I see in glpi.documents the row after execute the sentence, but, when I try to attach this document to a ticket, I get the error: (GLPIError("(ERROR_GLPI_ADD) [{'id': False, 'message': 'No tiene permisos para realizar esta acción.'}]"),) (Rights issue)

This is my code:


def upload_doc (conexion, path, nombre, ticket_id): # conexion = connection, path = file path, nombre = file name, ticket_id = itself xD
    logging.debug("Subiendo un documento: ", nombre)
    try:
        resultado_up = conexion.upload_document(nombre,path) # THIS WORKS FINE
        id_documento = resultado_up["id"] # I Take the document_id 
        logging.debug("Documento subido", resultado_up)
        logging.debug("Actualizando ticket: ", ticket_id)
        try: 
            resultado_ticket = conexion.add('Document_Item', {'documents_id':id_documento, 'itemtype':'Ticket','items_id':ticket_id}) # THIS FAILS
            logging.debug("Ticket" + str(ticket_id) + "Actualizado")
            return resultado_ticket
        except Exception as error:
            logging.error("No se ha podido actualizar el ticket: ", error)
    except Exception as error:
        logging.critical("No se ha podido subir el documento: ", error)
        return 0

If you want to view the python library it's here: https://di.pages.unistra.fr/glpi/python-glpi-api/#


Thank you very much!

Edit: My glpi version it's 9.5.5

Last edited by Drumhazzard (2021-11-05 17:12:39)

Offline

#2 2021-11-10 12:48:44

Drumhazzard
Member
Registered: 2011-09-19
Posts: 47

Re: Python API - Document_Item add Issues

After too much coffee, myself was find the solution, and I will share with all of you:


def glpi_upload_doc (conexion, path, nombre, ticket_id):
    logging.info(f'Subiendo un documento: {nombre}')
    try:
        resultado_up = conexion.upload_document(nombre,path)
        id_documento = resultado_up["id"]
        logging.info(f'Documento subido: {resultado_up}')
        logging.info(f'Actualizando ticket: {ticket_id}')
        try: 
            resultado_ticket = conexion.add('Document', {'id':id_documento, 'itemtype':'Ticket','items_id':ticket_id})
            logging.debug("Ticket" + str(ticket_id) + "Actualizado")
            #return resultado_ticket
        except Exception as error:
            logging.error("No se ha podido actualizar el ticket: ", error)
    except Exception as error:
        logging.critical("No se ha podido subir el documento: ", error)
        return 0

The key was in

conexion.add('Document', {'id':id_documento, 'itemtype':'Ticket','items_id':ticket_id})

Offline

Board footer

Powered by FluxBB