How to use the new api

Hello, is there a description how to use the new API?

There is some general discussion here

with preview here

https://deploy-preview-338--pihole-docs.netlify.app/api/


Your Pi-hole self-hosts a precise API documentation using the OpenAPI standard. This will always match your local Pi-hole's API version and works 100% offline. Check out https://pi.hole/api/docs

You can also check the version of current development-v6 online if you prefer this:

https://ftl.pi-hole.net/development-v6/docs/#overview

Its easier if you remove the password when playing around eg:

pihole -a -p
pihole setpassword

Here are some examples with curl adding and removing an adlist (via HTTP):

GET:

$ curl -s pi.hole/api/lists | jq '.lists[]|.address,.enabled'

"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
true
"https://dehakkelaar.nl/lists/cryptojacking_campaign.list.txt"
true
"https://gitlab.com/ZeroDot1/CoinBlockerLists/raw/master/list.txt"
true
"https://github.com/NCSC-NL/flubot/raw/main/dga/flubot_v4.8_202112.txt"
true

POST:

$ curl -s --request POST \
-d '{"address":"https://raw.githubusercontent.com/anudeepND/blacklist/master/facebook.txt","type":"block","enabled":false}' \
pi.hole/api/lists | jq

{
  "lists": [
    {
      "address": "https://raw.githubusercontent.com/anudeepND/blacklist/master/facebook.txt",
      "comment": null,
      "groups": [
        0
      ],
      "enabled": false,
      "id": 14,
      "date_added": 1698716782,
      "date_modified": 1698716782,
      "type": "block",
      "date_updated": 0,
      "number": 0,
      "invalid_domains": 0,
      "abp_entries": 0,
      "status": 0
    }
  ],
  "took": 0.012626886367797852
}

GET:

$ curl -s pi.hole/api/lists | jq '.lists[]|.address,.enabled'

"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
true
"https://dehakkelaar.nl/lists/cryptojacking_campaign.list.txt"
true
"https://gitlab.com/ZeroDot1/CoinBlockerLists/raw/master/list.txt"
true
"https://github.com/NCSC-NL/flubot/raw/main/dga/flubot_v4.8_202112.txt"
true
"https://raw.githubusercontent.com/anudeepND/blacklist/master/facebook.txt"
false

DELETE:

$ curl -s --request DELETE \
pi.hole/api/lists/https://raw.githubusercontent.com/anudeepND/blacklist/master/facebook.txt
$

GET:

$ curl -s pi.hole/api/lists | jq '.lists[]|.address,.enabled'

"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts"
true
"https://dehakkelaar.nl/lists/cryptojacking_campaign.list.txt"
true
"https://gitlab.com/ZeroDot1/CoinBlockerLists/raw/master/list.txt"
true
"https://github.com/NCSC-NL/flubot/raw/main/dga/flubot_v4.8_202112.txt"
true
1 Like

Note:

The v6 command to change the password is: pihole setpassword

1 Like

Old habits die hard :wink:

$ pihole -h
[..]
Options:
  setpassword           set the password for the web interface