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 2022-01-11 13:50:46

Dawood
Member
Registered: 2022-01-11
Posts: 2

How to set 'users_id_recipient' while creating tickets from API.

Hi guys,

I want to create tickets by admin session on behalf of users

So I use this:

curl --location --request POST 'https://glpi/apirest.php/ticket' \
--header 'Session-Token: rbm5e7utpij8h0mc1g0fe5pck9' \
--header 'Content-Type: application/json' \
--data-raw '{
"input": {
        "name": "Ticket",
        "content": "hi@gmail.com",
        "_users_id_requester": 130,
        "users_id_recipient": 130
}}
'


User requester has been set but users_id_recipient is set to session owner (admin's id in our case). And when I retrieve the ticket it does not have any sign of the user id.


Ticket detail response:
{
   "id": 59,
    "entities_id": "Root Entity",
    "name": "Ticket",
    "date": "2022-01-11 12:39:31",
    "closedate": null,
    "solvedate": null,
    "date_mod": "2022-01-11 12:39:31",
    "users_id_lastupdater": 2,
    "status": "In Progress",
    "users_id_recipient": 2,
    "requesttypes_id": "Helpdesk",
    "content": "hi@gmail.com",
    "urgency": 3,
    "impact": 3,
    "priority": 3,
    "itilcategories_id": 0,
    "type": 1,
    "global_validation": 1,
    "slas_id_ttr": 0,
    "slas_id_tto": 0,
    "slalevels_id_ttr": 0,
    "time_to_resolve": null,
    "time_to_own": null,
    "begin_waiting_date": null,
    "sla_waiting_duration": 0,
    "ola_waiting_duration": 0,
    "olas_id_tto": 0,
    "olas_id_ttr": 0,
    "olalevels_id_ttr": 0,
    "ola_ttr_begin_date": null,
    "internal_time_to_resolve": null,
    "internal_time_to_own": null,
    "waiting_duration": 0,
    "close_delay_stat": 0,
    "solve_delay_stat": 0,
    "takeintoaccount_delay_stat": 1,
    "actiontime": 0,
    "is_deleted": 0,
    "locations_id": 0,
    "validation_percent": 0,
    "date_creation": "2022-01-11 12:39:31",
}


Our requirements:
1: We want to be able to check if a ticket is created by a specific user in the ticket detail endpoint.
2: we want to be able to filter based on user id in the ticket list endpoint.

Is there any way to set pre-existing 'users_id_recipient' from API, or include '_users_id_requester' in the response of the list & detail of tickets to satisfy our requirement?

Offline

#2 2022-01-11 14:22:02

Dawood
Member
Registered: 2022-01-11
Posts: 2

Re: How to set 'users_id_recipient' while creating tickets from API.

An approach could be updating the newly created ticket to set the 'users_id_recipient' to the desired user id. Like bellow:

curl --location --request PUT 'https://glpi/apirest.php/ticket/59' \
--header 'Session-Token: rbm5e7utpij8h0mc1g0fe5pck9' \
--header 'Content-Type: application/json' \
--data-raw '{
"input": {
        "users_id_recipient": 130
}}
'


But I was wondering if there is a better way?

Last edited by Dawood (2022-01-11 14:22:28)

Offline

#3 2022-01-11 15:18:33

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

Re: How to set 'users_id_recipient' while creating tickets from API.

to get ticket by requester id : use search  endpoint :

apirest.php/search/Ticket/?is_deleted=0&as_map=0&criteria[0][link]=AND&criteria[0][field]=4&criteria[0][searchtype]=equals&criteria[0][value]=$userid


Trouver la panne avant de réparer...
GLPI10.0.16 (ubuntu 22.04 PHP8.1  Mariadb10.6 ) plugins : comportements 2.7.3 reports 1.16.0 formcreator 2.13.9, datainjection 2.13.5 fields 1.21.9

Offline

#4 2022-02-25 03:37:01

ensirq
Member
Registered: 2022-01-21
Posts: 1

Re: How to set 'users_id_recipient' while creating tickets from API.

Dawood wrote:

An approach could be updating the newly created ticket to set the 'users_id_recipient' to the desired user id. Like bellow:

curl --location --request PUT 'https://glpi/apirest.php/ticket/59' \
--header 'Session-Token: rbm5e7utpij8h0mc1g0fe5pck9' \
--header 'Content-Type: application/json' \
--data-raw '{
"input": {
        "users_id_recipient": 130
}}
'


But I was wondering if there is a better way?

Saw this somewhere:

if you want to add users to a ticket :

$url=$api_url . "/Ticket/".$ticket_id."/Ticket_User/";
method POST
$input='{ "input": {"tickets_id": '.$ticket_id.' ,"users_id": '.$user_id.',"type": "2","use_notification": "1"}}';

with type :
   // Requester  1;
   // Assign    2;
   // Observer  3;

Offline

Board footer

Powered by FluxBB