You are not logged in.
Pages: 1
Topic closed
Hello,
I need do a specific search by API to return some tickets.
This is I trying in Postman:
http://MYIP/apirest.php/search/Ticket?is_deleted=0&as_map=0&criteria[0][link]=AND&criteria[0][field]=9&criteria[0][searchtype]=notequals&criteria[0][value]=10&criteria[1][link]=AND&criteria[1][criteria][0][link]=AND&criteria[1][criteria][0][field]=5&criteria[1][criteria][0][searchtype]=equals&criteria[1][criteria][0][value]=1408&criteria[1][criteria][1][link]=OR&criteria[1][criteria][1][field]=5&criteria[1][criteria][1][searchtype]=equals&criteria[1][criteria][1][value]=865&criteria[1][criteria][2][link]=OR&criteria[1][criteria][2][field]=5&criteria[1][criteria][2][searchtype]=equals&criteria[1][criteria][2][value]=3062&search=Pesquisar&itemtype=Ticket
Error response: [
"ERROR",
"Critério de busca mal formulado.; ver documentação em seu navegador em http://MYIP/apirest.php/#ERROR"
]
This is my URL of GLPI GUI:
http://MYIP/front/ticket.php?is_deleted=0&as_map=0&criteria%5B0%5D%5Blink%5D=AND&criteria%5B0%5D%5Bfield%5D=9&criteria%5B0%5D%5Bsearchtype%5D=notequals&criteria%5B0%5D%5Bvalue%5D=10&criteria%5B1%5D%5Blink%5D=AND&criteria%5B1%5D%5Bcriteria%5D%5B0%5D%5Blink%5D=AND&criteria%5B1%5D%5Bcriteria%5D%5B0%5D%5Bfield%5D=5&criteria%5B1%5D%5Bcriteria%5D%5B0%5D%5Bsearchtype%5D=equals&criteria%5B1%5D%5Bcriteria%5D%5B0%5D%5Bvalue%5D=1408&criteria%5B1%5D%5Bcriteria%5D%5B1%5D%5Blink%5D=OR&criteria%5B1%5D%5Bcriteria%5D%5B1%5D%5Bfield%5D=5&criteria%5B1%5D%5Bcriteria%5D%5B1%5D%5Bsearchtype%5D=equals&criteria%5B1%5D%5Bcriteria%5D%5B1%5D%5Bvalue%5D=865&criteria%5B1%5D%5Bcriteria%5D%5B2%5D%5Blink%5D=OR&criteria%5B1%5D%5Bcriteria%5D%5B2%5D%5Bfield%5D=5&criteria%5B1%5D%5Bcriteria%5D%5B2%5D%5Bsearchtype%5D=equals&criteria%5B1%5D%5Bcriteria%5D%5B2%5D%5Bvalue%5D=3062&search=Search&itemtype=Ticket&start=0&_glpi_csrf_token=3dfca9c393921fd8d185cc88677626d3
It's the same way like GLPI GUI, only change the "%5b" and "%5d" by "[" and "]" respectively to run in Postman, but the error response it's the same.
Here an image to ilustrate glpi screen about what I'm talking:
How can I make this request correctly?
Last edited by mecmav (2020-01-24 22:17:59)
Offline
Update:
I've try convert the entire URL --> http://MYIP/front/ticket.php?is_deleted=0&as_map=0&criteria%5B0%5D%5Blink%5D=AND&criteria%5B0%5D%5Bfield%5D=9&criteria%5B0%5D%5Bsearchtype%5D=notequals&criteria%5B0%5D%5Bvalue%5D=10&criteria%5B1%5D%5Blink%5D=AND&criteria%5B1%5D%5Bcriteria%5D%5B0%5D%5Blink%5D=AND&criteria%5B1%5D%5Bcriteria%5D%5B0%5D%5Bfield%5D=5&criteria%5B1%5D%5Bcriteria%5D%5B0%5D%5Bsearchtype%5D=equals&criteria%5B1%5D%5Bcriteria%5D%5B0%5D%5Bvalue%5D=1408&criteria%5B1%5D%5Bcriteria%5D%5B1%5D%5Blink%5D=OR&criteria%5B1%5D%5Bcriteria%5D%5B1%5D%5Bfield%5D=5&criteria%5B1%5D%5Bcriteria%5D%5B1%5D%5Bsearchtype%5D=equals&criteria%5B1%5D%5Bcriteria%5D%5B1%5D%5Bvalue%5D=865&criteria%5B1%5D%5Bcriteria%5D%5B2%5D%5Blink%5D=OR&criteria%5B1%5D%5Bcriteria%5D%5B2%5D%5Bfield%5D=5&criteria%5B1%5D%5Bcriteria%5D%5B2%5D%5Bsearchtype%5D=equals&criteria%5B1%5D%5Bcriteria%5D%5B2%5D%5Bvalue%5D=3062&search=Search&itemtype=Ticket&start=0&_glpi_csrf_token=004a73c7619d4ebe2c37e56402b2ef13
from glpi GUI in this website: https://www.url-encode-decode.com/
and returns the URL to put in Postman.
Now when I try run this request, not get an error, but still in Login Page.
A image ilustrating this:
And the response in login screen:
Need some help to understand this and solve.
Thanks for now.
Offline
Try To remove &search=Pesquisar&itemtype=Rocker at url end
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
After try, try and try, I have a different error.
Using all these criterias
criteria[0][link]:AND
criteria[0][field]:9
criteria[0][searchtype]:notequals
criteria[0][value]:10
criteria[1][link]:AND
criteria[1][criteria][0][link]:AND
criteria[1][criteria][0][field]:5
criteria[1][criteria][0][searchtype]:equals
criteria[1][criteria][0][value]:1408
criteria[1][criteria][1][link]:OR
criteria[1][criteria][1][field]:5
criteria[1][criteria][1][searchtype]:equals
criteria[1][criteria][1][value]:865
criteria[1][criteria][2][link]:OR
criteria[1][criteria][2][field]:5
criteria[1][criteria][2][searchtype]:equals
criteria[1][criteria][2][value]:3062
I get a response ["ERROR", "Malformed search criteria; view documentation in your browser at http://MYIP/apirest.php/#ERROR"
And when using only the first criteria
criteria[0][link]:AND
criteria[0][field]:9
criteria[0][searchtype]:notequals
criteria[0][value]:10
I got a correct response..
Now when I try use more criterias from here
criteria[1][link]:AND
criteria[1][criteria][0][link]:AND
criteria[1][criteria][0][field]:5
criteria[1][criteria][0][searchtype]:equals
criteria[1][criteria][0][value]:1408
criteria[1][criteria][1][link]:OR
criteria[1][criteria][1][field]:5
criteria[1][criteria][1][searchtype]:equals
criteria[1][criteria][1][value]:865
criteria[1][criteria][2][link]:OR
criteria[1][criteria][2][field]:5
criteria[1][criteria][2][searchtype]:equals
criteria[1][criteria][2][value]:3062
Always returns error "malformed search".
It's possible to get response using that search like explained on the start of this post??
The example I'm referring is in this link https://ibb.co/qxgSFN2
Or my criterias are really setted wrong?
Offline
Using with backslashes like this
?criteria\[0]\[link]=AND&criteria\[0]\[field]=9&criteria\[0]\[searchtype]=notequals&criteria\[0]\[value]=10&criteria\[1]\[link]=AND&criteria\[1]\[criteria][0][link]=AND&criteria\[1]\[criteria][0][field]=5&criteria\[1]\[criteria][0][searchtype]=equals&criteria\[1]\[criteria][0][value]=1408&criteria\[1]\[criteria][1][link]=OR&criteria\[1]\[criteria][1][field]=5&criteria\[1]\[criteria][1][searchtype]=equals&criteria\[1]\[criteria][1][value]=865&criteria\[1]\[criteria][2][link]=OR&criteria\[1]\[criteria][2][field]=5&criteria\[1]\[criteria][2][searchtype]=equals&criteria\[1]\[criteria][2][value]=3062
returns all tickets
{
"totalcount": 151,
"count": 20,
"sort": 1,
"order": "ASC",
"data": .......
}
It's like the criterions don't be applied... Can I How fix this?
Offline
writing query like this seems to work ( i guess problem comes from carriages return)
$url="/search/Ticket/";
$url .="?criteria[0][link]=AND&criteria[0][field]=9&criteria[0][searchtype]=notequals&criteria[0][value]=10";
$url .="&criteria[2][link]=AND&criteria[2][criteria][0][link]=AND";
$url .="&criteria[2][criteria][0][field]=5&criteria[2][criteria][0][searchtype]=equals&criteria[2][criteria][0][value]=1408";
$url .="&criteria[2][criteria][1][link]=OR&criteria[2][criteria][1][field]=5&criteria[2][criteria][1][searchtype]=equals&criteria[2][criteria][1][value]=865";
$url .="&criteria[2][criteria][2][link]=OR&criteria[2][criteria][2][field]=5&criteria[2][criteria][2][searchtype]=equals&criteria[2][criteria][2][value]=3062";
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
writing query like this seems to work ( i guess problem comes from carriages return)
$url="/search/Ticket/"; $url .="?criteria[0][link]=AND&criteria[0][field]=9&criteria[0][searchtype]=notequals&criteria[0][value]=10"; $url .="&criteria[2][link]=AND&criteria[2][criteria][0][link]=AND"; $url .="&criteria[2][criteria][0][field]=5&criteria[2][criteria][0][searchtype]=equals&criteria[2][criteria][0][value]=1408"; $url .="&criteria[2][criteria][1][link]=OR&criteria[2][criteria][1][field]=5&criteria[2][criteria][1][searchtype]=equals&criteria[2][criteria][1][value]=865"; $url .="&criteria[2][criteria][2][link]=OR&criteria[2][criteria][2][field]=5&criteria[2][criteria][2][searchtype]=equals&criteria[2][criteria][2][value]=3062";
I can't urderstand a way to do it with Postman, So I do it directly in the code like you say, but get same error: Malformed criteria.
Update: I think it's because
$url .="?criteria[0][link]=AND&criteria[0][field]=9&criteria[0][searchtype]=notequals&criteria[0][value]=10";
$url .="&criteria[2][link]=AND&criteria[2][criteria][0][link]=AND";
goes from criterion 0 to 2 instead of 1
here my code
$api_url_glpi='MYGLPI/apirest.php';
...
initSession...
getFullSession...
$url_search="/search/Ticket/";
$url_search.="?&criteria[0][link]=AND&criteria[0][field]=9&criteria[0][searchtype]=notequals&criteria[0][value]=10";
$url_search.="&criteria[1][link]=AND&criteria[1][criteria][0][link]=AND";
$url_search.="&criteria[1][criteria][0][field]=5&criteria[1][criteria][0][searchtype]=equals&criteria[1][criteria][0][value]=1408";
$url_search.="&criteria[1][criteria][1][link]=OR&criteria[1][criteria][1][field]=5&criteria[1][criteria][1][searchtype]=equals&criteria[1][criteria][1][value]=865";
$url_search.="&criteria[1][criteria][2][link]=OR&criteria[1][criteria][2][field]=5&criteria[1][criteria][2][searchtype]=equals&criteria[1][criteria][2][value]=3062";
$url_search_complete=$api_url_glpi.$url_search;
echo "\n".$url_search_complete;
Here my result with the error: https://ibb.co/RBtc4vJ
After correct the criterion from 0 to 1, in GLPI GUI I get all tickets with this search.
But by API, getting Malformed search criteria
Last edited by mecmav (2020-01-27 14:43:13)
Offline
Anyone can help with this ?
Nobody never had "Malformed search criteria"?
Searching about this error, nearly haven't topics or results about that.
Offline
Update: using a test GLPI 9.4.5 this request returns all tickets that I want.
Why is not possible in 9.4.2?
Offline
ithink there was a bug in 9.4.2 fixed by :
https://github.com/glpi-project/glpi/pull/5889
see changelog.
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
ithink there was a bug in 9.4.2 fixed by :
https://github.com/glpi-project/glpi/pull/5889see changelog.
Thanks by the useful answer.
I applied this commit, and now returning correct response with desired tickets.
It's was really a bug and the fix works to me.
Thanks again!
Last edited by mecmav (2020-01-28 14:35:31)
Offline
Pages: 1
Topic closed