Search GLPI Via API

Asked

Viewed 1,077 times

0

I want to do a search via API in which return me certain data according to the parameters you set, ie:

To search all items I do a Get where you send the following:

https://.../apirest.php/search/Ticket/

This search returns me all tickets that exist.

What I want is to do this search in which define, for example, urgency=5.

https://.../apirest.php/search/Ticket/(...)

And that GET just return me tickets with urgency equal to 5.

Example documentation: (Since the parameters and category vary from item to item)

http://path/to/glpi/apirest.php/search/Monitor?\
criteria\[0\]\[link\]\=AND\
\&criteria\[0\]\[itemtype\]\=Monitor\
\&criteria\[0\]\[field\]\=23\
\&criteria\[0\]\[searchtype\]\=contains\
\&criteria\[0\]\[value\]\=GSM\
\&criteria\[1\]\[link\]\=AND\
\&criteria\[1\]\[itemtype\]\=Monitor\
\&criteria\[1\]\[field\]\=1\
\&criteria\[1\]\[searchtype\]\=contains\
\&criteria\[1\]\[value\]\=W2\
\&range\=0-2\&&forcedisplay\[0\]\=1'
  • And what API is this? Have you read the documentation of it to check if there is such a parameter?

  • In the documentation there is an example but not in C#, I do not know how to do identico in C#...

1 answer

0

Long live,

First, search the link ".../apirest.php/listSearchOptions/Ticket" the id of the field you want to search for

Check this result for the available filter type, for example:

"12": {
    "name": "Status",
    "table": "glpi_tickets",
    "field": "status",
    "datatype": "specific",
    "nosearch": false,
    "nodisplay": false,
    "available_searchtypes": [
        "equals"
    ],
    "uid": "Ticket.status"
},

now, add to your search

http://path/to/glpi/apirest.php/search/Monitor?\
...
&criteria[0][field]=12
&criteria[0][searchtype]=equals
&criteria[0][value]=2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.