Hello, I am setting up a new instance of Piwigo using v16, which is great so far. Of note, I will be enabling TOTP, and I'd like to set up an API key for scheduled tasks (see below).
Ages ago, I found and set up a script to automatically generate thumbnails on photos that were missing them. Over the years, that script has been updated to work with newer versions of Piwigo as they came out.
I'm looking for help with v16, to make sure the script works, and specifically to update the script to use an API key instead of a name and password. Can anyone offer help with this?
The script in its current form is at:
https://github.com/GJSchaller/piwigo-thumb-generate
Thank you!
Offline
If I understand your script it looks like you probably can remove the login and saving cookies portion (lines 13 and 31). Then change the calls to pwg.getMissingDerivatives to include the Authorization header and the API key ("id:secret") generated on the Piwigo profile page for the user you want to use on lines 15 and 28.
wget -nv --header='Authorization: pkid-xxxxxxxx-xxxxxxxxxxxxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -O missing.json "http://(Path-To-Piwigo)/ws.php?format=json&method=pwg.getMissingDerivatives"
Offline
Thank you for the help on this! It's mostly working, but I am getting an "Authorization Failed" message - I'll try to troubleshoot a bit and report back if I can't figure it out.
Offline
Since I updated to the latest version (16.1.0) I have been having trouble invoking any of the admin only WS methods. I have not figured out why that is happening yet (the web services were working fine before the update) but I thought I would mention it in case it is something that is affecting other people as well.
Offline
This is the error I am getting:
geoffrey@TrueNAS:/mnt/data/scripts/1-CRON$ ./piwigo-thunb-generate.sh http://photos.aiskon.net/ws.php?format=json&method=pwg.session.login: 2025-12-02 16:03:14 ERROR 405: This method requires HTTP POST. geoffrey@TrueNAS:/mnt/data/scripts/1-CRON$
Offline
The pwg.session.login method does require the payload to be sent as POST data but you shouldn't need to call that method at all if you have a valid Authorization header on the call to pwg.getMissingDerivatives. Try commenting out or removing the pwg.session.login line from your script.
Offline
My current script:
set -e
cd /mnt/data/scripts/1-CRON/
wget -nv --header='Authorization: pkid-20251202-REDACTED:REDACTED' -O missing.json "http://photos.aiskon.net/ws.php?format=json"
while [ `wc -c missing.json | awk '{print $1}'` -gt 50 ]
do
sed -e 's/[\\\"]//g' \
-e 's/{stat:ok,result:{next_page:[0-9]*,urls:\[//' \
-e 's/{stat:ok,result:{urls:\[//' \
-e 's/\]}}/\n/' \
-e 's/,/\n/g' \
-e 's/\&b=[0-9]*//g' missing.json | \
while read line ; do
wget -nv -O /dev/null $line
done
wget -nv --header='Authorization: pkid-20251202-REDACTED:REDACTED' -O missing.json "http://photos.aiskon.net/ws.php?format=json"
done
rm missing.jsonThe results:
geoffrey@TrueNAS:/mnt/data/scripts/1-CRON$ ./piwigo-thunb-generate.sh http://photos.aiskon.net/ws.php?format=json: 2025-12-02 16:21:59 ERROR 501: Missing "method" name. geoffrey@TrueNAS:/mnt/data/scripts/1-CRON$
Offline
Try adding the following between format=json and the closing quote on your wget lines.
&method=pwg.getMissingDerivatives
Offline
Result:
geoffrey@TrueNAS:/mnt/data/scripts/1-CRON$ ./piwigo-thunb-generate.sh Username/Password Authentication Failed. geoffrey@TrueNAS:/mnt/data/scripts/1-CRON$
Offline
Do you get the same result if you just run the wget command by itself?
I ran the following script against my testing server and walked through the list of files as expected. Sorry, but I'm really not sure why you are getting that error.
#!/bin/sh
set -e
cd /home/dcg
wget -nv --header='Authorization: pkid-20251202-XXXXX:XXXXX' -O missing.json "https://MY-PIWIGO-SERVER/ws.php?format=json&method=pwg.getMissingDerivatives"
while [ `wc -c missing.json | awk '{print $1}'` -gt 50 ]
do
sed -e 's/[\\\"]//g' \
-e 's/{stat:ok,result:{next_page:[0-9]*,urls:\[//' \
-e 's/{stat:ok,result:{urls:\[//' \
-e 's/\]}}/\n/' \
-e 's/,/\n/g' \
-e 's/\&b=[0-9]*//g' missing.json | \
while read line ; do
wget -nv -O /dev/null $line
done
wget -nv --header='Authorization: pkid-20251202-XXXXX:XXXXX' -O missing.json "https://MY-PIWIGO-SERVER/ws.php?format=json&method=pwg.getMissingDerivatives"
done
rm missing.jsonOffline
Okay I did a bit more testing and I am now consistently getting the same "Username/Password Authentication Failed." when I run that wget command against 16.1.0 but it works when run against 16.0.0 on the same server. The only change is installing the upgrade or manually reverting back to 16.0.0.
Offline
I'm using the Docker image, so I am on 16.1 at the moment. Who do I tag to let them know this may be an issue?
Offline
I have made a thread specifically about this issue I am having with the web services API on 16.1.0 but I'm just a user so I don't know who needs to be tagged.
https://piwigo.org/forum/viewtopic.php? … 16#p193616
Offline
Hello,
There is a change regarding API keys in version 16.1.0: the header is no longer "Authorization" but "X-PIWIGO-API". [Github] Piwigo issue #2460
Offline
That did it! Thank you! I'll post the working code in a bit.
Offline