API call in v6 to disable pihole for a short time

Hi,

Tried to get the v6 api to do what is mentioned here for v5 Is there an API command to disable ad blocking?

Can someone point me in the right direction how to do this in one http link?

Tried things like htttp://pihole:8080/api/dns/blocking?blocking=false

But can’t get it to work. What is the right syntax?

This is a GET request, however, you will have to use POST.

The API is described using OpenAPI specs and will be easier to find once release. For now, please check out Pi-hole API documentation and more specifically POST /dns/blocking.

Did some research and this link is what I came up with

http://192.168.178.171:8080/api/dns/blocking/?blocking=false

What am I doing wrong?

This is a GET request. What tools are you using? Like Python, Bash, cURL, ... for making the request? This will help me to provide a suitable example for you.

Hi,

What I want to do is give the family a url to click on to easily disable pihole for a few minutes. So this url is accessed through safari on iPads and iPhones.

Sorry for mixing up post en get by the way

Unfortunately, this isn't possible with the redesigned API following REST principles. Any "clickable link" will always trigger a GET request and those are not allowed to change any settings - incl. the blocking mode - cfm. from the link above:

Use GET requests to retrieve resource representation/information only – and not modify it in any way. As GET requests do not change the resource’s state, these are said to be safe methods.

Ok thanks for that, I‘ll automate it through nodered than. That should be possible.

Sidenote stability of v6 is brilliant. Also the high level of caching makes that only 25% of our traffic (between 40.000 and 80.000 requests per 24 hours) uses a request to my unbound setup.
Impressive

If you do go down the route of using NodeRED to automate it, would you mind sharing your flow, either here or on the NodeRED forums? I’m sure it is something that many people would be interested in.

Yeah made it work :wink: created a url named “disable” on nodered installation. Which in response tells how long the pihole is disabled. I’ve set it to 10 minutes. Tweak it if you like. One tweak I will do is add another pihole install so I can get redundant pihole established and also disable both installs at the same time

Below the export of the flow:

[
    {
        "id": "e05bef77a0d32682",
        "type": "tab",
        "label": "Disable pihole",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "5a7c93e546f768ac",
        "type": "http request",
        "z": "e05bef77a0d32682",
        "name": "",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://pi.hole:8080/api/dns/blocking",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 1010,
        "y": 400,
        "wires": [
            []
        ]
    },
    {
        "id": "21739583887237d4",
        "type": "json",
        "z": "e05bef77a0d32682",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 810,
        "y": 400,
        "wires": [
            [
                "5a7c93e546f768ac"
            ]
        ]
    },
    {
        "id": "de1762d74105c86e",
        "type": "function",
        "z": "e05bef77a0d32682",
        "name": "JSON for blocking",
        "func": "msg.payload = \"{\\\"blocking\\\":false,\\\"timer\\\": 600}\";\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 610,
        "y": 400,
        "wires": [
            [
                "21739583887237d4"
            ]
        ]
    },
    {
        "id": "fc0eede929621a33",
        "type": "http in",
        "z": "e05bef77a0d32682",
        "name": "",
        "url": "/disable",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 290,
        "y": 400,
        "wires": [
            [
                "de1762d74105c86e",
                "d3122bb0cf9ca780"
            ]
        ]
    },
    {
        "id": "d3122bb0cf9ca780",
        "type": "template",
        "z": "e05bef77a0d32682",
        "name": "Webpagina response",
        "field": "payload",
        "fieldType": "msg",
        "format": "html",
        "syntax": "mustache",
        "template": "<!DOCTYPE html>\n<html>\n<head>\n\t<title>Pihole turned off for 10 minutes</title>\n\n\t<h1>Pihole is disabled for 10 minutes</h1>\n</head>\n<body>\n\n<p>Pihole is disabled for 10 minutes</p>\n</body>\n</html>",
        "output": "str",
        "x": 620,
        "y": 320,
        "wires": [
            [
                "7fda1b66e45479d4"
            ]
        ]
    },
    {
        "id": "7fda1b66e45479d4",
        "type": "http response",
        "z": "e05bef77a0d32682",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 790,
        "y": 320,
        "wires": []
    }
]
1 Like

Thanks very much !

1 Like

A post was split to a new topic: Pi-hole automation in Homeassistant