I
Immich4mo ago
jaimetur

API request

Hello, I’m investigating how to use Immich API to create my own script to upload photos, create albums from folders and so on. For the time being Inwas able to connect to my Immich account using the endpoint /auth/login which provide me a bearer token that I would like to use for my next APO requests as part of the header. But at this point I am not able to do a simple API request to create a new Album with a name “myTestAlbum” and using the bearer token received during login procedure. I would appreciate if someone could help me with this. PS: I am using Python to call those API requests.
21 Replies
Immich
Immich4mo ago
:wave: Hey @jaimetur, 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
Immich
Immich4mo ago
Checklist I have... 1. :blue_square: verified I'm on the latest release(note that mobile app releases may take some time). 2. :blue_square: read applicable release notes. 3. :blue_square: reviewed the FAQs for known issues. 4. :blue_square: reviewed Github for known issues. 5. :blue_square: tried accessing Immich via local ip (without a custom reverse proxy). 6. :blue_square: uploaded the relevant information (see below). 7. :blue_square: 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.
GitHub
immich-app immich · Discussions
Explore the GitHub Discussions forum for immich-app immich. Discuss code, ask questions & collaborate with the developer community.
GitHub
Issues · immich-app/immich
High performance self-hosted photo and video management solution. - Issues · immich-app/immich
Tempest
Tempest4mo ago
Immich-go supports this already, might be something to look into if you're just re-inventing the wheel. If there's another motive then disregard the comment
schuhbacca
schuhbacca4mo ago
You should post the actual request you are creating. Also this is more of what API keys are used for
jaimetur
jaimeturOP4mo ago
I know that I can do it with Immich-go, but I would like to integrate it on my script that aims to automate the whole process of migration from Google Photos into Synology Photos or Immich in just one click (for Synology the process is finished and working properly but for Immich I need to investigate a bit more on the use of the API)
Tempest
Tempest4mo ago
interesting. Would you happen to be building a script from synology photos -> immich as well then?
jaimetur
jaimeturOP4mo ago
My request is simple. A simple payload with the album name but I don’t know which header should I pass to use my bearer token
jaimetur
jaimeturOP4mo ago
Yes, if I manage to make Immich API work, the intention is to do all the migration process between Google Photos to Synology Photos or Immich and also from Synology Photos to Immich
Tempest
Tempest4mo ago
if you complete that I'd be interested in it 👀
jaimetur
jaimeturOP4mo ago
Yes I saw this API doc, but it doesn’t show how to pass the bearer token
Tempest
Tempest4mo ago
if you click "authorize" in the top right, it'll provide options but I'd probably suggest api-key versus bearer token
jaimetur
jaimeturOP4mo ago
Sure, you can follow my project on GitHub (https://github.com/jaimetur/OrganizeTakeoutPhotos) API key is more difficult to understand for not experienced users, that’s why I would prefer to let users authenticate with their own mail/pass
jaimetur
jaimeturOP4mo ago
Interesting project. Thanks I have found on the install-wizard.sh this piece of code that give me a clue on how to insert the bearer token in the API request header library_id=$(curl -s --location --request POST "http://127.0.0.1:2283/api/libraries" \ --header 'Content-Type: application/json' \ --header "Authorization: Bearer $accessToken" \ --data-raw "{ "ownerId": "$user_id", \ "importPaths": ["$local_mount_path"], "name": "Existing Media" }")
Tempest
Tempest4mo ago
ah my bad, I thought you were having issues retrieving the token. But in any case that project did make use of bearer
jaimetur
jaimeturOP4mo ago
I guess that I should include this on the header: --header 'Content-Type: application/json' \ --header "Authorization: Bearer $accessToken" \
Tempest
Tempest4mo ago
then again that was visible with the api example
curl -L '/api/albums' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer FixEB9hpcl1D3uDlsPsk6WyB3ZtBdOchcBAQYhrRAY' \
-d '{
"albumName": "string",
"albumUsers": [
{
"role": "editor",
"userId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
],
"assetIds": [
"3fa85f64-5717-4562-b3fc-2c963f66afa6"
],
"description": "string"
}'
curl -L '/api/albums' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer FixEB9hpcl1D3uDlsPsk6WyB3ZtBdOchcBAQYhrRAY' \
-d '{
"albumName": "string",
"albumUsers": [
{
"role": "editor",
"userId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
],
"assetIds": [
"3fa85f64-5717-4562-b3fc-2c963f66afa6"
],
"description": "string"
}'
https://immich.app/docs/api/create-album if choosing to use bearer as an auth
jaimetur
jaimeturOP4mo ago
I am using this header on my request but it does not work: HEADERS = { "Authorization": f"Bearer {SESSION_TOKEN}", "Content-Type": "application/json" }
Tempest
Tempest3mo ago
what's the full request? not sure if you made any progres, however I did manage to get my albums out of synology photos. Here's the snippet in case it saves you any time
sudo su - postgres

psql -d synofoto

\COPY ( SELECT a.id, a.name as albumName, r.id_item, u.filename, f.name as dirName,
CONCAT(f.name, '/', u.filename) as path
FROM public.normal_album AS a
JOIN many_item_has_many_normal_album AS r ON a.id = r.id_normal_album
JOIN unit AS u ON r.id_item = u.id
JOIN folder AS f ON u.id_folder = f.id
) TO '/volume1/user/postgres/albums.csv' WITH CSV HEADER;
sudo su - postgres

psql -d synofoto

\COPY ( SELECT a.id, a.name as albumName, r.id_item, u.filename, f.name as dirName,
CONCAT(f.name, '/', u.filename) as path
FROM public.normal_album AS a
JOIN many_item_has_many_normal_album AS r ON a.id = r.id_normal_album
JOIN unit AS u ON r.id_item = u.id
JOIN folder AS f ON u.id_folder = f.id
) TO '/volume1/user/postgres/albums.csv' WITH CSV HEADER;
jaimetur
jaimeturOP3mo ago
Thank you. I finally manage to do it from my Script BTW, I will paste here the repository to the tool that I am developing (not sure if this is the place to post it, feel free to delete if not or move to a more appropriate place). The tool is still in alpha release, so, so you can expect bugs or some functionalities still not complete but may be useful for some of you https://github.com/jaimetur/CloudPhotoMigrator

Did you find this page helpful?