How do I do an API call and get the images like google photo's service?

I'm currently building an external app, and i'm looking at the documentation and it doesn't really show how does one get the images
29 Replies
Immich
Immich10mo ago
:wave: Hey @ChiefDucky, Thanks for reaching out to us. Please follow the recommended actions below; 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 compose ps docs - Reverse Proxy: https://immich.app/docs/administration/reverse-proxy Checklist 1. :blue_square: I have verified I'm on the latest release(note that mobile app releases may take some time). 2. :blue_square: I have read applicable release notes. 3. :blue_square: I have reviewed the FAQs for known issues. 4. :blue_square: I have reviewed Github for known issues. 5. :blue_square: I have tried accessing Immich via local ip (without a custom reverse proxy). 6. :blue_square: I have uploaded the relevant logs, docker compose, and .env files, making sure to use code formatting. 7. :blue_square: I have 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) If this ticket can be closed you can use the /close command, and re-open it later if needed.
Alex Tran
Alex Tran10mo ago
You can use the following format http://server-ip:2283/api/assets/<asset-id>/thumbnail?size=preview
ChiefDucky
ChiefDuckyOP10mo ago
it would just be a really really simple api request for taken date = "datetime format" ah yes, but i'm looking for something like i kinda don't really get it sorry
ChiefDucky
ChiefDuckyOP10mo ago
yea i'm right there?
Alex Tran
Alex Tran10mo ago
what is still unclear?
ChiefDucky
ChiefDuckyOP10mo ago
yea so let's say i need to very simply request images taken on a date
Alex Tran
Alex Tran10mo ago
This is the endpoint http://server-ip:2283/api/search/metadata POST
Alex Tran
Alex Tran10mo ago
this is the body
No description
ChiefDucky
ChiefDuckyOP10mo ago
yessir but how would i query sorry i'm quite new to this
Alex Tran
Alex Tran10mo ago
The API document link above showed you a few ways here
No description
Alex Tran
Alex Tran10mo ago
using curl, javascript, go or Python
ChiefDucky
ChiefDuckyOP10mo ago
thanks payload = json.dumps({ "checksum": "string", "city": "string", "country": "string", "createdAfter": "string", "createdBefore": "string", "deviceAssetId": "string", "deviceId": "string", "encodedVideoPath": "string", "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "isArchived": True, "isEncoded": True, "isFavorite": True, "isMotion": True, "isNotInAlbum": True, "isOffline": True, "isVisible": True, "lensModel": "string", "libraryId": "3fa85f64-5717-4562-b3fc-2c963f66afa6", "make": "string", "model": "string", "order": "asc", "originalFileName": "string", "originalPath": "string", "page": 0, "personIds": [ "3fa85f64-5717-4562-b3fc-2c963f66afa6" ], "previewPath": "string", "size": 0, "state": "string", "takenAfter": "string", "takenBefore": "string", "thumbnailPath": "string", "trashedAfter": "string", "trashedBefore": "string", "type": "IMAGE", "updatedAfter": "string", "updatedBefore": "string", "withArchived": False, "withDeleted": True, "withExif": True, "withPeople": True, "withStacked": True }) headers = { 'Content-Type': 'application/json', 'Accept': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text) oh sorry not to spam my bad what is the return of this? like would it response me a text?
Alex Tran
Alex Tran10mo ago
The assetIds
ChiefDucky
ChiefDuckyOP10mo ago
then how does one get the image?
Alex Tran
Alex Tran10mo ago
Then You can use the following format http://server-ip:2283/api/assets/<asset-id>/thumbnail?size=preview to get the image file
ChiefDucky
ChiefDuckyOP10mo ago
aha oh so thumbnail is the full resolution?
Alex Tran
Alex Tran10mo ago
https://immich.app/docs/api/view-asset Possible values: [preview, thumbnail] preview is the small thumb you see on the timeline thumbnail is the large file in the detail view
ChiefDucky
ChiefDuckyOP10mo ago
api_key1 = get_key_by_name(conn,'immich') Immich server details immich_server_url = 'http://100.85.11.26:2283/api/search/metadata' access_token = api_key1 Function to get the latest images def get_latest_images(): headers = { 'Authorization': f'Bearer {access_token}' } params = { 'size': 10, # Number of images to fetch 'type': 'IMAGE', 'order': 'desc' } response = requests.post(f'{immich_server_url}/api/search/smart', headers=headers, json=params) if response.status_code == 200: return response.json().get('items', []) else: st.error('Failed to fetch images') return [] sorry brother but let's say this is my python script how do i send a request i'm super lost right
Alex Tran
Alex Tran10mo ago
use backtick for code please http://server-ip:2283/api/assets/<asset-id>/original this is to get the original sorry can't walk you through this, please use Google
ChiefDucky
ChiefDuckyOP10mo ago
def get_latest_images():
headers = {
'Authorization': f'Bearer {access_token}'
}
params = {
'size': 10, # Number of images to fetch
'type': 'IMAGE',
'order': 'desc'
}
response = requests.post(f'{immich_server_url}/api/search/smart', headers=headers, json=params)
if response.status_code == 200:
return response.json().get('items', [])
else:
st.error('Failed to fetch images')
return []
def get_latest_images():
headers = {
'Authorization': f'Bearer {access_token}'
}
params = {
'size': 10, # Number of images to fetch
'type': 'IMAGE',
'order': 'desc'
}
response = requests.post(f'{immich_server_url}/api/search/smart', headers=headers, json=params)
if response.status_code == 200:
return response.json().get('items', [])
else:
st.error('Failed to fetch images')
return []
ah this is how you send codes
ChiefDucky
ChiefDuckyOP10mo ago
No description
ChiefDucky
ChiefDuckyOP10mo ago
Hey bro is this norma? like expected until i put in more query?
ChiefDucky
ChiefDuckyOP10mo ago
like when i do 172.19.01:238 it ping me that
No description
ChiefDucky
ChiefDuckyOP10mo ago
but then oncce i actually do the search/metadata it doesn't work
Frey
Frey6mo ago
Hey @Alex, sorry for taking this old thread up, but what's the difference between "takenAfter" vs "createdAfter" in the POST /search/metadata? Same goes for "takenBefore" vs "createdBefore". With "createdBefore" + "createdAfter" I'm getting results only for 2023 and 2024 from my Immich instance, an empty results for all other years 2010-2022, but with "takenBefore" + "takenAfter" the results are there.
Alex Tran
Alex Tran6mo ago
iirc takenAfter is about the date the photo is taken while created is the date the file is ingested into Immich
Frey
Frey6mo ago
Thank you! Not sure that the behaviour I described above is intended, so FYI
Alex Tran
Alex Tran6mo ago
Thanks! I believe we are using taken property for our search

Did you find this page helpful?