Immich API getRandom returns empty list
in the documentation it mentions the getRandom api endpoint. However, when I make an api call, it returns an empty list. Has this functionality been implemented yet?
35 Replies
Can you post the actual request?
The curl command i am using is right out of the documentation:
curl -L -X GET 'photos.hostname.com/api/asset/random?count=1' \
-H 'Accept: application/json' \
-H 'x-api-key: xxxxxxxxxxxxxxxxxxxx'
Do you have any asset on your instance?
yes, a little under 11 thousand
😛
all other api calls return expected results.
Hmm
I am seeing this as well
yeah there might be a bug with that endpoint
@Daniel Any thoughts on this?
ah wait
Can you try
?count=5
?
http://IP:2283/api/asset/random?count=1
Same result.
strange, if I put int
?count=<number>
then it works for me
which server version are you on?
Can you try to make the request from the browser?I am on 1.79.1. I just tried through the web browser and i get the same thing.
Can you update to 1.80 and try again?
I believe there is a bug fix for this endpoint in 1.80
Ok, it does now return a result when count=1, but only about 40% of the time.
hmm really?
confirmed
this is weird
can you help to file a bug report on GitHub?
Sure.
Thank you
Bug report submitted.
Appreciate it!
Thank you.
@bubter Hm this should really not be happening anymore.
I'll have a look at it later
Ok @bubter, unfortunately I'm not able to reproduce the issue. On version 1.80 I always get the exact number of assets specified by count, or one asset if count is not specified.
The api key actually belongs to the user that owns the 11k assets? (or at least more than one)
Could you try running this as described here?
The command returns a result every time.
Yes, the api-key belongs to the correct user. Either way, there are no users with a blank library.
Furthermore, this behavior is not limited to an api-key, as it has the same behavior when using my browser.
Oh that's weird. The api basically only calls that query lol
Thats.... intriguing.
Could Nginx Proxy Manager somehow affect it? I don't see how/why it would return an empty list, but its the only thing between me and the server.
You mentioned though that other api endpoints work for you, right?
Yes, I have had no issues with other endpoints.
Ok, I have just tried making the call using http and the host directly, no change.
Do you have multiple users?
yes. 4 in total, including admin.
Do they all have assets?
The admin does not, but the rest do.
I'm guessing you are somehow using the admin id in the api call or query for some reason.
If you want to verify, you can try this - change the start command for the postgres container to:
That will log all the queries. After a restart, hit the endpoint a few times and then send the logs over here. We can validate the params for the query are correct.
Oh wait.
Nope, this is a bug
ok, I just uploaded a single asset to the admin account. No change.

line 437 is filtering by owner id, but line 438 is doing an offset as a random number based on the total asset count.
It should be
SELECT COUNT(*) - $2, ... FROM ASSETS _WHERE ownerId = $1
@bubter It should be fixed in 1.81.1