Photo delete endpoint on Node API

Platform(s): API (the new/Node-based API)

URLs (aka web addresses) of any pages, if relevant: https://api.inaturalist.org/v1/photos/:id

Description of need: I’m building a Lightroom plugin to synchronize between Lightroom and iNaturalist, and one of the things it can do is remove photos from iNaturalist. I’m currently using the older Rails-based API for this particular call (since it does support photo deletion), but for consistency with the rest of my code would like to be able to use the Node-based API.

Feature request details: DELETE https://api.inaturalist.org/v1/photos/:id should work, have the same authentication rules etc as the Rails-based API, and return results consistent with other DELETE requests.

not sure if it matters, but i believe if you remove a photo record from an observation (or you delete the observation) and it is no longer tied to anything, it will delete the photo record (although the image files on the server don’t seem to get deleted, which has been previously reported, i think).

Thanks :) When I was testing I found that deleting an observation did indeed delete all the photos attached to it*, but that deleting an observation_photo did not. I might have made a mistake with that, I’ll try again.

i haven’t tested in a while, but my note from https://forum.inaturalist.org/t/is-it-possible-to-use-the-api-to-attach-an-existing-photo-record-to-an-observation/29814/9 seems to indicate that photo records will be deleted:

also, here’s the other thing i mentioned earlier related to image files not getting properly deleted even if the photo records are: https://forum.inaturalist.org/t/image-files-stored-on-media-server-dont-seem-to-be-getting-deleted-when-observations-and-photo-records-are-getting-deleted/36460.

1 Like

Ah, interesting. I’m not doing any PUT to /observations/:id; I was testing with DELETE /observation_photos/:id. But it seems I got muddled during my testing, because deleting the observation_photo does indeed delete the photo:

russell@zip:~ $ curl --header "Authorization: $JWT" --header 'Content-Type: multipart/form-data' https://api.inaturalist.org/v1/observation_photos -F "observation_photo[observation_id]=153292740" -F file=@_DSC1365.jpg
{"id":247119772,"observation_id":153292740,"photo_id":264879492,"position":null,"created_at":"2023-04-03T13:39:22.911-07:00","updated_at":"2023-04-03T13:39:22.911-07:00","old_uuid":null,"uuid":"afeb8635-3144-4269-8f02-8bfde80c007c","created_at_utc":"2023-04-03T20:39:22.911Z","updated_at_utc":"2023-04-03T20:39:22.911Z","photo":{"id":264879492,"user_id":4590187,"native_photo_id":null,"created_at":"2023-04-03T13:39:21.344-07:00","updated_at":"2023-04-03T13:39:21.344-07:00","native_page_url":null,"native_username":null,"native_realname":null,"license":3,"subtype":null,"native_original_image_url":null,"uuid":"418a12fb-83f4-4d6b-ac9c-46b52864c965","file_extension_id":null,"file_prefix_id":null,"width":1600,"height":1280,"license_code":"cc-by-nc-nd","license_name":"Creative Commons Attribution-NonCommercial-NoDerivs License","license_url":"http://creativecommons.org/licenses/by-nc-nd/4.0/","attribution":"(c) rcloran, some rights reserved (CC BY-NC-ND)","type":"LocalPhoto","square_url":"https://www.inaturalist.org/attachment_defaults/local_photos/square.png","thumb_url":"https://www.inaturalist.org/attachment_defaults/local_photos/thumb.png","small_url":"https://www.inaturalist.org/attachment_defaults/local_photos/small.png","medium_url":"https://www.inaturalist.org/attachment_defaults/local_photos/medium.png","large_url":"https://www.inaturalist.org/attachment_defaults/local_photos/large.png"}}%

russell@zip:~ $ curl -X DELETE --header 'Accept: application/json' --header "Authorization: $JWT" 'https://api.inaturalist.org/v1/observation_photos/247119772'
""%
russell@zip:~ $ curl -v --header "Authorization: $JWT" https://www.inaturalist.org/photos/264879492 -o /dev/null 2>&1 | grep HTTP/1.1
> GET /photos/264879492 HTTP/1.1
< HTTP/1.1 404 Not Found

It does look like the photo URLs in the POST response are not correct; I’ll report a bug for that, but, it also looks like the objects aren’t properly deleted out of S3 similar to what you reported for observation deletion before.

I put together an implementation for this. I saw that the Rails app didn’t actually respond properly to JSON requests, so it wasn’t really implemented for the Rails-based API, it just happens to work fine for my client which ignores the response body.

https://github.com/rcloran/inaturalist/commit/6b914c094fae430dc840ff71f08495c6371c851c
https://github.com/rcloran/inaturalistjs/commit/32f280816bb7d6cdef701519b5a190f4566ae1f1
https://github.com/rcloran/iNaturalistAPI/commit/9b04f8dcea5a52570a6c7bd9d696aa45c7cf5c5b

I’d be happy to add tests, create pull requests, and make any requested changes if this feature request is approved.

it seems like this has been resolved.