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
Daniel
Daniel2y ago
Does Account Settings -> Libraries -> Scan All Libraries the job for you?
Quietsy
QuietsyOP2y ago
Yes, that works great
Daniel
Daniel2y ago
Oh sorry you meant like automatically, right?
Quietsy
QuietsyOP2y ago
Yes, from the cli or automatically
Daniel
Daniel2y ago
Unfortunately, I don't think that is possible atm Maybe helpful though? @etnoy
etnoy
etnoy2y ago
there's no way yet, but you can also just call the REST api and it'll do it
Quietsy
QuietsyOP2y ago
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:
curl -L -X GET 'https://immich.domain.com/api/library' -H 'Accept: application/json' -H 'x-api-key: yourapikey'
curl -L -X GET 'https://immich.domain.com/api/library' -H 'Accept: application/json' -H 'x-api-key: yourapikey'
Then replace libraryid with the library id, immich.domain.com and yourapikey in the following and run:
curl -L -X POST 'https://immich.domain.com/api/library/libraryid/scan' -H 'Content-Type: application/json' --data-raw '{"refreshAllFiles": false, "refreshModifiedFiles": true }' -H 'x-api-key: yourapikey'
curl -L -X POST 'https://immich.domain.com/api/library/libraryid/scan' -H 'Content-Type: application/json' --data-raw '{"refreshAllFiles": false, "refreshModifiedFiles": true }' -H 'x-api-key: yourapikey'
krelltunez
krelltunez2y ago
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}
Daniel
Daniel2y ago
Could you post your script?
krelltunez
krelltunez2y ago
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'"
Daniel
Daniel2y ago
Since you've got a " before refreshAllFiles you're command will basically end there Which obviously then would become an invalid command
krelltunez
krelltunez2y ago
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
Daniel
Daniel2y ago
Actually, I don't think it would need to be But not 100% sure
krelltunez
krelltunez2y ago
OK, I'll see if I can figure it out. I'm not a skilled scripter.
Daniel
Daniel2y ago
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 though
krelltunez
krelltunez2y ago
Tried without the outer " and it threw another error. I'll try the above. This worked. Thanks!!!
TFJ
TFJ2y ago
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
Daniel
Daniel2y ago
You pinged the wrong Daniel lol
TFJ
TFJ2y ago
Oops Agh, sorry about that. I miss read this the first time. Thank you! I’ll try it out. @Quietsy
Allram
Allram2y ago
@TFJ - Documentation for getting the Library ID is here: https://immich.app/docs/api/get-all-for-user
Allram
Allram2y ago
so basically this as a curl:
curl -L 'https://DOMAIN-OR-IP-TO-IMMICH/api/library' \
-H 'Accept: application/json' \
-H 'x-api-key: APIKEYHERE'
curl -L 'https://DOMAIN-OR-IP-TO-IMMICH/api/library' \
-H 'Accept: application/json' \
-H 'x-api-key: APIKEYHERE'
And you put in your API key to authorize as your user.
TFJ
TFJ2y ago
@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.

Did you find this page helpful?