Issue adding domains to the list with nodejs and node-fetch

Please follow the below template, it will help us to help you!

Expected Behaviour:

Link added to blocklist from discord bot input, When adding links via the http API it goes through as approved, and the domains should be added through the list for example 1talking.net

Actual Behaviour:

Console and Audit logs show no new query's added to the black or white list,

Debug Token:

Do I understand this correctly that you are trying to programmatically add domains to the block list? If so, have you ensured that you do not have any logic errors.

From the little information provided, it is not clear what you are doing, or have gone about trying to achieve your goals. More details might help in getting assistance.

I have updated it a small tad but thats all the information I can give at the time, Im using the HTTP Api

Please elaborate. More details would help.

Did you find a discord script that is trying to add domains to gravity?

No, Im making my own bot using discord js and nodejs (node-fetch) Im trying to add a domain to the adlist Blacklist, Im currently trying to use the http api, However im struggling to be able to add the domains to this list. Is it possible using the http API?

Please post the script you are using.

Please upload a debug log and post just the token URL that is generated after the log is uploaded by running the following command from the Pi-hole host terminal:

pihole -d

or do it through the Web interface:

Tools > Generate Debug Log


const PIHOLE_URL = 'Redacted';
const API_TOKEN = 'Redacted';

const addDomainToPiHole = async (fetch, domain) => {
    try {
        console.log(`Adding domain: ${domain}`);
        const response = await fetch(`${PIHOLE_URL}?list=black&add=${encodeURIComponent(domain)}&auth=${API_TOKEN}`);
        const result = await response.json();
        if (result.success) {
            console.log(`Domain ${domain} added successfully!`);
        } else {
            console.log(`Failed to add domain ${domain}: ${result.message}`);
        }
    } catch (error) {
        console.error('Error adding domain:', error);
    }
};


const fetchAndAddDomains = async (fetch, url) => {
    try {
        console.log(`Fetching domains from: ${url}`);
        const response = await fetch(url);
        if (!response.ok) throw new Error(`Failed to fetch list. Status: ${response.status}`);

        const text = await response.text();
        const domains = text.split('\n')
            .filter(line => line && !line.startsWith('#')) 
            .map(domain => domain.trim()) 
            .filter(domain => /^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(domain)); 

        console.log(`Fetched ${domains.length} valid domains.`);

        for (const domain of domains) {
            await addDomainToPiHole(fetch, domain);
        }
    } catch (error) {
        console.error('Error fetching or adding domains:', error);
    }
};


const run = async () => {
    const fetch = (await import('node-fetch')).default; 
    await fetchAndAddDomains(fetch, 'https://v.firebog.net/hosts/Easylist.txt');
};

run().catch(console.error);

Replied to the wrong person @jfb

Is there a way that I can Modify the Gravity.db Database file to add these list with my nodeJS bot

https://tricorder.pi-hole.net/TKhDiftK/