Details about my system: Debian, Apache2 with Pi-Hole
What I have changed since installing Pi-hole: Changed /var/www/html/admin to /var/www/html/pihole
I have problems with the API. I have set it up so that I can access the API via a subdomain.
So "sub.domain.tld/pihole/api.php..." shows me the json data. Now when I try to include it with this code, I get this error: "Uncaught (in promise) SyntaxError: Unexpected token 'F', "Failed COR".... is not valid JSON"
Well, it might help the developers rule out issues. So, if they suggest that, why not give it a shot.
Backing up to your question to me:
The URL of your page or the URL used by your Pi-hole API call. Your code block calling the Pi-hole API is using https, based in the code snippet you shared. I cannot imagine that is the real URL you are using, but it suggests https and not http:
The URL shows my current directory (/var/www/html). By attaching /pihole/api.php to the url I get /var/www/html/pihole/api.php.
So in the end I call the api.php with the appropriate args, summaryRaw & auth, over https, yes.
But how should that affect the functionality of the API? Because in the browser everything is displayed normally via https.
But, originally I had it as http URL, only there the HTML page where I want to embed the API complained that it can't load an http page in an https page. And the HTML must be loaded in HTTPS unfortunately.
It does not work. The only difference I find is that I see the following on the HTML page in the browser at the API URL: [Browser Dev Tools -> Elements -> api.php/... -> Preview]
> Failed CORS: #URL HTML SITE# vs #IP PIHOLE#, #EXTRA API URL#, pi.hole, localhost
If I now add my URL to ../scripts/pihole/php/auth.php I get this:
Failed CORS: #URL HTML SITE# vs #IP PIHOLE#, #EXTRA API URL#, pi.hole, localhost, #EXTRA API URL#
So in the end the same URL only twice. So that doesn't seem to be the problem.
In addition, I have now set that I can also call the extra URL for the API via http. Because that could have been a problem. But now, as already mentioned, I also have this error on the HTML page:
Mixed Content: The page at 'https://#URL HTML SITE#/' was loaded over HTTPS, but requested an insecure resource 'http://#EXTRA API URL#/pihole/api.php?summaryRaw&auth=#MY AUTH TOKEN#'. This request has been blocked; the content must be served over HTTPS.
If I then add the following line to the HTML file, this error goes away, but the Cors error remains.
That's done with for me. I have found another way, but it is probably not suitable for others. If someone knows a solution to the problem, they can post it here for other users who find this post and are looking for a solution to their problem.
Opening new topics for the same thing will only lead to a bunch of unanswered topics that have no relation or link to each other. That wastes everyone's time and efforts to help you. It will also lead to your early forced retirement from this community.