How to get Device.ID if all what I know is device IP or MAC?

My query looks like:

curl -i 'http://localhost:7557/devices/?query=%7B%22InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress%22%3A%22" . $deviceMAC . "%22%7D'

Generally it works fine but is there a better way to get only “Device.ID” if all what I know is device IP or MAC?

I had this same issue.
I followed this example (https://github.com/genieacs/genieacs/wiki/Virtual-Parameters) to create a virtual parameter the first time every new device registers with the ACS. Once that exists I query the API by virtual Parameters MAC to obtain the Device.ID.
I suspect you could do the same with the IP as well but it would need to update if the IP changes.

What you want to do is a projection. This allows you to query GenieACS and bring back only the data you want.

curl -i 'http://localhost:7557/devices/?query=%7B%22InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANIPConnection.1.MACAddress%22%3A%22". $deviceMAC . "%22%7D&projection=_id'