Scan External Libraries from the cli
Hello, is there a way to scan external libraries from the cli or somehow schedule these scans?
24 Replies
Does Account Settings -> Libraries -> Scan All Libraries the job for you?
Yes, that works great
Oh sorry you meant like automatically, right?
Yes, from the cli or automatically
Unfortunately, I don't think that is possible atm
Maybe helpful though? @etnoy
there's no way yet, but you can also just call the REST api and it'll do it
Awesome, I'll look into it, thanks!
For anyone else who needs it, to get the library id replace
immich.domain.com
and yourapikey
in the following and run:
Then replace libraryid
with the library id, immich.domain.com
and yourapikey
in the following and run:
This command works in shell, but I get an error when trying to run it from a script. Here's the error I get:
{"message":"Expected property name or '}' in JSON at position 1","error":"Bad Request","statusCode":400}
Could you post your script?
Yeah, let me clean it up.
docker exec immich_server sh -c "curl -L -X POST 'IMMICH_URL/api/library/LIBRARY_ID/scan' -H 'Content-Type: application/json' --data-raw '{"refreshAllFiles": false, "refreshModifiedFiles": true }' -H 'x-api-key: API_KEY'"
Since you've got a " before refreshAllFiles you're command will basically end there
Which obviously then would become an invalid command
Ah, so would I use ' instead of "?
The whole command needs to be inside "" right? Not sure how to do that when the command includes ""s
Actually, I don't think it would need to be
But not 100% sure
OK, I'll see if I can figure it out. I'm not a skilled scripter.
This however wouldn't work either because there are also single quotes ' used in the command. So you would need to escape the " within the command. So
\"
This should definitely work docker exec immich_server sh -c "curl -L -X POST 'IMMICH_URL/api/library/LIBRARY_ID/scan' -H 'Content-Type: application/json' --data-raw '{\"refreshAllFiles\": false, \"refreshModifiedFiles\": true }' -H 'x-api-key: API_KEY'"
If you can remove the outer ", you wouldn't need to escape them thoughTried without the outer " and it threw another error. I'll try the above.
This worked. Thanks!!!
Might seem obvious for some, but how do I figure out my 🆔 (library_ID) or if I want to the ID than I scan for all users, or users individually.
@Quietsy @Daniel
I'm using a script to run fswatch to trigger a command to scan the library on file system change direclty on macos as I dont know how to this through docker, I was able to make this work great on photoprism but I can't figure the library_id to make this work with IMMICH.
Setup: Running IMMICH on docker desktop for macos, and managing through portainer
You pinged the wrong Daniel lol
Did you read my message? https://discord.com/channels/979116623879368755/1156527569072566354/1156535007515529256
Oops
Agh, sorry about that. I miss read this the first time. Thank you! I’ll try it out. @Quietsy
@TFJ - Documentation for getting the Library ID is here:
https://immich.app/docs/api/get-all-for-user
so basically this as a curl:
And you put in your API key to authorize as your user.
@Allram @Quietsy
Thank you, Its the fist time I'm using anything
API
and curl
related, so i'm trying to get by... not understanding all I'm doing. I was able to get a script going that does what I need, inspired by a post on Reddit and ChatGPT:
https://www.reddit.com/r/immich/comments/16pmme7/comment/k3b5l8f/?utm_source=share&utm_medium=web2x&context=3
I'm sharing for anyone else who is interested.
setup:
-macOS sonoma 14.0
- Apple Mac Mini M1
- Docker Desktop
- IMMICH 1.82.1 (server)
- IMMICH app 1.82
- fswatch installed on macos.
- homebrew installed on macos
This is mean't to auto scan and remove offline
files on system file change
by watch folder
Given, I have no idea if its the most efficient way? but it works for me for the moment, the removeOffline
command seems to miss files sometimes, not sure why but that is why I added the curl command twice. I have not tested this too long, but here we go. See the Pastebin below:
https://pastebin.com/RbbZFwi2
For the ones who are only interested by the command without using fswatch to monitor changes, this will also automitcally retrieve the external library 🆔endpoint=http://192.168.1.10:2240/api/library #or https://immich.domain.com/api/library
api_key=create_API_inIMMICH
# Make the GET request to retrieve data
response=$(curl -vv --url "$endpoint" --header "x-api-key: $api_key")
id=$(echo "$response" | jq --raw-output '.[] | select(.type=="EXTERNAL") | .id')
# Use the retrieved ID for both the scan and remove commands
curl -vv --url "$endpoint/$id/scan" --data-raw "$id" --header "x-api-key: $api_key"
curl -vv -L -X POST "$endpoint/$id/removeOffline" --header "x-api-key: $api_key"
Happy for suggestion and feedback to implement on the pastebin script 🤷♂️Reddit
AnnoyedVelociraptor's comment on "Clarifications about Immich exter...
Explore this conversation and more from the immich community
Pastebin
IMMICH AND PHOTOPRISM AUTO SCAN - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.