I
Immich•4mo ago
Bretos

API request via cURL

I feel like I'm an idiot, I'm trying to trigger library rescan via API ( https://immich.app/docs/api/scan-library ) To do that, I need to get library ID(s) - https://immich.app/docs/api/get-all-libraries/ Here's my command:
curl -X POST "https://immich.example.com/api/libraries?direction=getAllLibraries" \
-H "x-api-key: API_Key_created_in_user_settings_webui" \
-H "Content-Type: application/json" \
-d '{"ownerId": "id_of_my_user_with_ext_library"}'
curl -X POST "https://immich.example.com/api/libraries?direction=getAllLibraries" \
-H "x-api-key: API_Key_created_in_user_settings_webui" \
-H "Content-Type: application/json" \
-d '{"ownerId": "id_of_my_user_with_ext_library"}'
the response I get: {"id":"9adf1f07-5d22-49a0-a853-6c143b00cd4c","ownerId":"my_user_id","name":"New External Library","createdAt":"2025-01-02T15:11:08.046Z","updatedAt":"2025-01-02T15:11:08.046Z","refreshedAt":null,"assetCount":0,"importPaths":[],"exclusionPatterns":["**/@eaDir/**","**/._*"]} the effect I get: my user has just created a new external library. Currently existing are missing from the reponse. WTH am I doing wrong here??
30 Replies
Immich
Immich•4mo ago
:wave: Hey @Bretos, Thanks for reaching out to us. Please carefully read this message and follow the recommended actions. This will help us be more effective in our support effort and leave more time for building Immich :immich:. References - Container Logs: docker compose logs docs - Container Status: docker ps -a docs - Reverse Proxy: https://immich.app/docs/administration/reverse-proxy - Code Formatting https://support.discord.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline#h_01GY0DAKGXDEHE263BCAYEGFJA Checklist I have... 1. :ballot_box_with_check: verified I'm on the latest release(note that mobile app releases may take some time). 2. :ballot_box_with_check: read applicable release notes. 3. :ballot_box_with_check: reviewed the FAQs for known issues. 4. :ballot_box_with_check: reviewed Github for known issues. 5. :ballot_box_with_check: tried accessing Immich via local ip (without a custom reverse proxy). 6. :ballot_box_with_check: uploaded the relevant information (see below). 7. :ballot_box_with_check: tried an incognito window, disabled extensions, cleared mobile app cache, logged out and back in, different browsers, etc. as applicable (an item can be marked as "complete" by reacting with the appropriate number) Information In order to be able to effectively help you, we need you to provide clear information to show what the problem is. The exact details needed vary per case, but here is a list of things to consider: - Your docker-compose.yml and .env files. - Logs from all the containers and their status (see above). - All the troubleshooting steps you've tried so far. - Any recent changes you've made to Immich or your system. - Details about your system (both software/OS and hardware). - Details about your storage (filesystems, type of disks, output of commands like fdisk -l and df -h). - The version of the Immich server, mobile app, and other relevant pieces. - Any other information that you think might be relevant. Please paste files and logs with proper code formatting, and especially avoid blurry screenshots. Without the right information we can't work out what the problem is. Help us help you ;) If this ticket can be closed you can use the /close command, and re-open it later if needed. Successfully submitted, a tag has been added to inform contributors. :white_check_mark:
Daniel
Daniel•4mo ago
What is ?direction=getAllLibraries supposed to do? 👀 Also, only admin users can trigger a library scan Also, there's a cronjob you can customize that already re-scans the libraries every specified interval
Bretos
BretosOP•4mo ago
OK, I think I've lost my head somewhere after last year and before current one. What's the correcth URL for getAllLibraries then? does API require any additional arguments, like direction? I want to trigger scan manually after a specific sync operation is completed, as inotify is funky over NFS
Daniel
Daniel•4mo ago
/api/libraries is correct, you need an admin api key though And no, it does not require any additional arguments, otherwise the docs would say so :)
Bretos
BretosOP•4mo ago
admin api = api created via "setting" of an user that is an admin?
Daniel
Daniel•4mo ago
Yep
Bretos
BretosOP•4mo ago
curl -X POST "https://immich.example.com/api/libraries" \
-H "x-api-key: admin_api_key" \
-H "Content-Type: application/json" \
-H 'Accept: application/json' \
-d '{"ownerId": "5db5eb69-da0a-43f3-9715-1795923f0cc6"}'

{"id":"7656512b-98d2-4d94-a976-d26c2fb6e504","ownerId":"5db5eb69-da0a-43f3-9715-1795923f0cc6","name":"New External Library","createdAt":"2025-01-02T15:35:21.397Z","updatedAt":"2025-01-02T15:35:21.397Z","refreshedAt":null,"assetCount":0,"importPaths":[],"exclusionPatterns":["**/@eaDir/**","**/._*"]}#
curl -X POST "https://immich.example.com/api/libraries" \
-H "x-api-key: admin_api_key" \
-H "Content-Type: application/json" \
-H 'Accept: application/json' \
-d '{"ownerId": "5db5eb69-da0a-43f3-9715-1795923f0cc6"}'

{"id":"7656512b-98d2-4d94-a976-d26c2fb6e504","ownerId":"5db5eb69-da0a-43f3-9715-1795923f0cc6","name":"New External Library","createdAt":"2025-01-02T15:35:21.397Z","updatedAt":"2025-01-02T15:35:21.397Z","refreshedAt":null,"assetCount":0,"importPaths":[],"exclusionPatterns":["**/@eaDir/**","**/._*"]}#
still the same issue, creates new library and doesn't list the existing one. when I POST at curl -X POST "https://immich.example.com/api/libraries/getAllLibraries" \ I get the response: {"message":"Cannot POST /api/libraries/getAllLibraries","error":"Not Found","statusCode":404,"correlationId":"0c92j5ys"}#
Daniel
Daniel•4mo ago
Yes, this endpoint does not exist Why are you sending {ownerId: }?
Bretos
BretosOP•4mo ago
because otherwise {"message":["ownerId must be a UUID","ownerId should not be empty","ownerId must be a string"],"error":"Bad Request","statusCode":400,"correlationId":"al7r8dpl"}# so how do I call directly to getAllLibraries?
Daniel
Daniel•4mo ago
You don't call getAllLibraries The endpoint is called libraries Are you using AI for this? This is odd and should not happen Which version is your Immich server on?
Bretos
BretosOP•4mo ago
Lol, we're doomed if I am 1.123.0
Daniel
Daniel•4mo ago
Yeah, I am just confused where you get all this stuff from, e.g. the ?direction= param
Bretos
BretosOP•4mo ago
I tried some random stuff after it didn't work like I expected, mainly from https://github.com/immich-app/immich/discussions/13081
Daniel
Daniel•4mo ago
Can you try it against the demo instance?
Daniel
Daniel•4mo ago
As that works for me
No description
Bretos
BretosOP•4mo ago
# curl -X POST "https://demo.immich.app/api/libraries/" \
-H "x-api-key: pTpFSM4gaVlFSZ2IVOTUDU6KgewmVEhR8tyI4wUjJs" \
-H 'Accept: application/json'
{"message":["ownerId must be a UUID","ownerId should not be empty","ownerId must be a string"],"error":"Bad Request","statusCode":400,"correlationId":"x7bxmiwa"}
# curl -X POST "https://demo.immich.app/api/libraries/" \
-H "x-api-key: pTpFSM4gaVlFSZ2IVOTUDU6KgewmVEhR8tyI4wUjJs" \
-H 'Accept: application/json'
{"message":["ownerId must be a UUID","ownerId should not be empty","ownerId must be a string"],"error":"Bad Request","statusCode":400,"correlationId":"x7bxmiwa"}
Daniel
Daniel•4mo ago
Oh wait I see your issue
Daniel
Daniel•4mo ago
No description
Bretos
BretosOP•4mo ago
but then...
curl -L "https://demo.immich.app/api/libraries/" \
-H 'Accept: application/json' \
-H "x-api-key: pTpFSM4gaVlFSZ2IVOTUDU6KgewmVEhR8tyI4wUjJs"
[{"id":"d7648f56-f5a3-4d41-a5f1-2b13e6c88ba9","ownerId":"aff6f1bc-c40e-40d4-a7f1-832762b8e407","name":"New External Library","createdAt":"2025-01-02T12:43:36.176Z","updatedAt":"2025-01-02T14:27:26.760Z","refreshedAt":"2025-01-02T14:27:26.755Z","assetCount":0,"importPaths":[],"exclusionPatterns":["**/@eaDir/**","**/._*"]},{"id":"9d02aa99-7175-4d25-b58f-2b28b3faa538","ownerId":"0c389df9-5476-4c01-acf9-1ccefb0448f7","name":"New External Library","createdAt":"2025-01-02T13:12:04.835Z","updatedAt":"2025-01-02T14:27:26.755Z","refreshedAt":"2025-01-02T14:27:26.752Z","assetCount":0,"importPaths":[],"exclusionPatterns":["**/@eaDir/**","**/._*"]}]
curl -L "https://demo.immich.app/api/libraries/" \
-H 'Accept: application/json' \
-H "x-api-key: pTpFSM4gaVlFSZ2IVOTUDU6KgewmVEhR8tyI4wUjJs"
[{"id":"d7648f56-f5a3-4d41-a5f1-2b13e6c88ba9","ownerId":"aff6f1bc-c40e-40d4-a7f1-832762b8e407","name":"New External Library","createdAt":"2025-01-02T12:43:36.176Z","updatedAt":"2025-01-02T14:27:26.760Z","refreshedAt":"2025-01-02T14:27:26.755Z","assetCount":0,"importPaths":[],"exclusionPatterns":["**/@eaDir/**","**/._*"]},{"id":"9d02aa99-7175-4d25-b58f-2b28b3faa538","ownerId":"0c389df9-5476-4c01-acf9-1ccefb0448f7","name":"New External Library","createdAt":"2025-01-02T13:12:04.835Z","updatedAt":"2025-01-02T14:27:26.755Z","refreshedAt":"2025-01-02T14:27:26.752Z","assetCount":0,"importPaths":[],"exclusionPatterns":["**/@eaDir/**","**/._*"]}]
Daniel
Daniel•4mo ago
Exactly You were POSTing But this is a GET endpoint
Bretos
BretosOP•4mo ago
lol
Daniel
Daniel•4mo ago
It returns all external libraries, which is to be expected no?
Bretos
BretosOP•4mo ago
let me try that on my instance yeah I just assumed they have different names without checking that first, that's why I deleted my message after checking it 😄
Daniel
Daniel•4mo ago
Ah lol I am surprised the POST gave you anything tbh
Bretos
BretosOP•4mo ago
OMG one would think that after enough years one can write a simple api request on one's own
Daniel
Daniel•4mo ago
😅 Happens to the best
Bretos
BretosOP•4mo ago
and then we get here anyway it works, thank you @Daniel !
Daniel
Daniel•4mo ago
And I didn't spot it immediately either :D
Bretos
BretosOP•4mo ago
yeah post created new ext library
Daniel
Daniel•4mo ago
Ooooohh And that requires an ownerId That makes so much sense actually lol

Did you find this page helpful?