Updating Ad lists programatically

I have a custom dockerized pihole instance that I am using to deploy multiple instances of pihole.

I used to be able to drop new adlists into /etc/pihole/adlists.list and it would pick up the lists from there for gravity updates.

Now I can't do this as of 5.X

What's the official recommended way of doing this?

For now, I'm dropping a one-shot s6 service that runs after _piholeFTL to manually insert rows into /etc/pihole/gravity.db.

I'm not really thrilled with this approach because I feel I shouldn't be directly touching the database (schema changes and so on in newer versions).

I don't want to manually log in to change this because all of this is getting pushed via ansible + docker compose templates.

This version of Pi-hole was released nearly four years ago.

This kind of functionality change should be expected when moving between major versions.

Pi-hole v5.0 was released 4 years ago and there were many updates since. You will probably find many other differences (current version is v5.18.2).

Suggestion:

If you just updated from v4 to v5, my suggestion is to try v6 (still in development, but most functions are already working).

v6 allows using a REST API to update lists.

This is a call to add a list:

The code above is using javascript/jQuery, but if you want to use the command line you can create a curl command using the same endpoint.

Yes, I was not expecting things to be stable between major versions.

I'm moving away from standalone copies of my services - I have 5.X that I am actively using but I never found an automated way to do what I wanted in a clean way.

Is the REST API only available in 6.X? I'm fine with making calls using cURL.

Looks like something like the following in 6.X works fine for me. Still need to create the container for 6.X and so forth but this is at least promising.

curl --header "Content-Type application/json" --request POST --data "{ 'address': '$(address)', 'comment': 'Imported by pihole-config.sh', 'type': 'block' }" "http://localhost/api/lists"

Thanks for an actual response.

As I said, v6 is still in development, but v6 API is already a lot more expended than v5 API, with more endpoints and options.

If you really want to keep v5, you can use curl to call api.php. It's not an actual REST API, but it will work just like the web interface AJAX calls: