I couldn’t find any quick references about accessing the Pihole API so I created this page.
Pihole is a great app for blocking internet advertising that was originally designed to be run on a raspberry pi. It blocks known advertisers’ domains at the DNS level by effectively null routing requests destined to serve ads. It can be run on VMs, Raspberry Pis and bare metal servers.
Here are the steps to access the pihole’s rest api. I’m using curl in this example, but you can integrate it with OpenHAB or any other system that can talk REST.
Most of the useful API endpoints the pihole provides wisely require authentication. After searching around the net I found that I could pass
&token=A_VALID_SESSION_TOKEN to authenticate to the pihole for a session. Unfortunately, this is a temporary auth token and wasn’t suitable for my needs. After more digging, I found the gem I needed:
&auth=WEBPASSWORD. Sounds great, but where do I obtain this password? You simply log onto your pihole instance or server and run:
How convenient. It’s stored right there in the Piholes vars config file. Copy this password (hash, base64encoded string, whatever you want to call it)
curl and the ultra useful
jq commands in my scripts. If you don’t have
jq and work with anything JSON you should probably install it.
Refer to the official pihole api documentation here.
your.pihole.address with the IP or hostname of your Pihole and the
auth=956e54... with your Pihole’s WEBPASSWORD
View List of configured forward destinations