You are not logged in.
Hi,
How can I search for a single location via API by name criteria (text) and return the completename, id and other informations?
I'm trying to get a single location by name via API but my criteria is not working as expected. Tested on 9.5.5
"apirest.php/search/location/?criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=MyLocationValue" is returning:
{
"totalcount": 40,
"count": 40,
"sort": "1",
"order": "ASC",
"data": [
{
"1": "MyLocationValue1",
"80": "Entity"
},
{
"1": "MyLocationValue2",
"80": "Entity"
},
{
"1": "MyLocationValue3",
"80": "Entity"
},
And then, when I try to get without "search", I get all of my location values:
apirest.php/location/?criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=MyLocationValue
[
{
"id": 1,
"entities_id": 0,
"is_recursive": 1,
"name": "TestLocation",
"locations_id": 0,
"completename": "TestLocation",
"comment": "",
"level": 1,
"ancestors_cache": "[]",
"sons_cache": null,
"address": "Address 1",
"postcode": "00000000",
"town": "Anytown",
"state": "Anystate",
"country": "CountryX",
"building": "50",
"room": "132",
"latitude": "-23.58518273584577",
"longitude": "-46.671032309532166",
"altitude": "",
"date_mod": "2020-02-15 14:59:49",
"date_creation": "2020-02-15 14:59:49",
"links": [
{
"rel": "Entity",
"href": "https://myservicedesk/apirest.php/Entity/0"
}
]
},
{
"id": 2,
"entities_id": 0,
"is_recursive": 1,
"name": "TestLocation2",
"locations_id": 0,
"completename": "TestLocation2",
"comment": "",
"level": 1,
"ancestors_cache": "[]",
"sons_cache": null,
"address": "Address 2",
"postcode": "00000000",
"town": "Anytown2",
"state": "Anystate2",
"country": "CountryY",
"building": "235",
"room": "",
"latitude": "-23.54520706799414",
"longitude": "-46.690725088119514",
"altitude": "",
"date_mod": "2020-02-15 15:01:49",
"date_creation": "2020-02-15 15:01:49",
"links": [
{
"rel": "Entity",
"href": "https://myservicedesk/apirest.php/Entity/0"
}
"id": 3,
"entities_id": 0,
"is_recursive": 1,
"name": "MyLocationValue",
"locations_id": 0,
"completename": "MyLocationValue",
"comment": "",
"level": 1,
"ancestors_cache": "[]",
"sons_cache": null,
"address": "Address 3",
"postcode": "00000000",
"town": "Anytown3",
"state": "Anystate3",
"country": "CountryZ",
"building": "235",
"room": "",
"latitude": "-23.54520706799414",
"longitude": "-46.690725088119514",
"altitude": "",
"date_mod": "2020-02-15 15:01:49",
"date_creation": "2020-02-15 15:01:49",
"links": [
{
"rel": "Entity",
"href": "https://myservicedesk/apirest.php/Entity/0"
}
If not possible, is there any way besides criteria that I can get only one Location information by name?
Thanks in advance
Last edited by stevansantos (2022-03-11 18:28:49)
Offline
Hi,
I'm using GLPI 9.4.6 and this url works :
http://localhost/glpi/apirest.php/search/Location/?criteria[0][link]=AND&criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=myLocation
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
Hi,
I'm using GLPI 9.4.6 and this url works :http://localhost/glpi/apirest.php/search/Location/?criteria[0][link]=AND&criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=myLocation
Thanks for your response. I'm using 9.5.5 and I've tested on 9.5.7 too but it's not working. Do you know another way that I can try to gather this information?
Offline
it also works on my 9.5.5 test instance...
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
it also works on my 9.5.5 test instance...
Thanks LaDenrée! I found out what was missing. It works on 9.5.5 and newer versions like you said, I just add rawdata=true into search criteria.
To anyone who has the same question: To get Location ID you must use apirest.php/search/Location/?criteria[0][link]=AND&criteria[0][field]=1&criteria[0][searchtype]=contains&criteria[0][value]=LocationTargetValue&rawdata[0]=true where LocationTargetValue is the Location you need to find the ID.
It will return:
"raw": {
"id": 123,
"currentuser": "userfromapi",
"entities_id": 0,
"is_recursive": 1,
"ITEM_Location_1": "LocationTargetValueName",
>> "ITEM_Location_1_id": 123, <<
"ITEM_Location_80": "Entity"
ITEM_Location_1_id is the Location ID that you've searched. It will work showing 1 information only if you search for the exact name of Location. If you not specify the exact Location, you might find two or more ITEM_Location_1_id inside raw data.
Offline