[API] [v5] How to retrieve domain groups?

Hello,

This time I'm working with the list api endpoint to add the ability to list domains, add/remove domains.

I have a question about the output of:
/admin/api.php?list=&auth=

Taking the following output as an example for the white list:
{"data":[{"id":1,"type":0,"domain":"<domain_1>","enabled":1,"date_added":1665532180,"date_modified":1697407161,"comment":"Added from Query Log","groups":[0]},{"id":24,"type":0,"domain":"<domain_2>","enabled":1,"date_added":1670065233,"date_modified":1697407877,"comment":"Added from Query Log","groups":[0,5,8]}]}

How are groups stored in Pi-hole database? I mean, what the numbers (groups:0,5,8...) mean in that case?

Taking a first look they could be retrieve as as per the generated array (order), but the order if the numbers and the numbers themselves don't match with the groups on my Pi-hole server.

For example: I have the following groups: Default, Telemetry, Others, Malware, Ads. And the groups retrieve by the API for the 2nd domain from the above code are: 0,5,8.

From this I can think:

  • The number 0 corresponds (always) with the Default group. (tested)
  • The rest of numbers of the generated array don't match with any of the elements of my list, nor position in the array (I don't have 8 groups, only 5), and the one matching the middle element of the array (5) doesn't match with such position on the Pihole WebUI panel.

So, is there any way by which we can get the list of groups from our Pi-hole server via API? Or at least understand how are they stored and retrieved by the API, so I can build a separate pre-build array on my project, matching the array positions of the previous api call with the ones from my project.

I think those are the ids from the 'group' table.

You should be able to verify by:

pihole-FTL sqlite3 /etc/pihole/gravity.db "SELECT * FROM 'group';"

Right. The numbers were the ids of every group in the db.

Thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.