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
: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_01GY0DAKGXDEHE263BCAYEGFJAChecklist
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.
FAQ | Immich
User
GitHub
Issues · immich-app/immich
High performance self-hosted photo and video management solution. - Issues · immich-app/immich
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
You should post the actual request you are creating.
Also this is more of what API keys are used for
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)
interesting. Would you happen to be building a script from synology photos -> immich as well then?
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
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
if you complete that I'd be interested in it 👀
Yes I saw this API doc, but it doesn’t show how to pass the bearer token
if you click "authorize" in the top right, it'll provide options
but I'd probably suggest api-key versus bearer token
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
https://github.com/1-tempest/immich-install-wizard/blob/96650ad13ddc37c9e119554090dd059d3e6477b3/install.sh#L865 is something that might get you started
https://immich.app/docs/api/login
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"
}")
ah my bad, I thought you were having issues retrieving the token. But in any case that project did make use of bearer
I guess that I should include this on the header:
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $accessToken" \
then again that was visible with the api example
https://immich.app/docs/api/create-album
if choosing to use bearer as an auth
I am using this header on my request but it does not work:
HEADERS = {
"Authorization": f"Bearer {SESSION_TOKEN}",
"Content-Type": "application/json"
}
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
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