//! Example: Delete assets //! //! This example demonstrates how to delete assets from Immich. //! //! WARNING: This will actually delete photos. Use with caution! //! //! This example uses environment variables for configuration: //! - IMMICH_URL: The Immich server URL (defaults to http://localhost:2283) //! - IMMICH_API_KEY: Your API key (required) //! //! IMPORTANT: Run this against a test instance only. This operation permanently //! removes assets from the server. use immich_sdk::Client; #[tokio::main] async fn main() -> Result<(), Box> { // Configure the client from environment variables let url = std::env::var("IMMICH_URL").unwrap_or_else(|_| "http://localhost:2283".to_string()); let api_key = std::env::var("IMMICH_API_KEY").expect("IMMICH_API_KEY environment variable not set"); // Create a client let client = Client::from_url(&url)?.with_api_key(api_key); // List existing assets let assets = client.assets().list().execute().await?; println!("Found {} assets", assets.len()); if assets.is_empty() { println!("No assets to delete. Run upload_photos first."); return Ok(()); } // Get the first asset details let first_id = assets[0].id; println!("Getting details for asset: {}", first_id); let asset = client.assets().get(first_id).execute().await?; println!("Asset: {} ({})", asset.original_file_name, asset.id); // Delete a single asset println!("\nDeleting single asset..."); client.assets().delete().id(first_id).execute().await?; println!("Asset deleted successfully"); // Batch delete (if there are more assets) if assets.len() > 1 { println!("\nBatch deleting remaining assets..."); let ids_to_delete: Vec<_> = assets.iter().skip(1).take(2).map(|a| a.id).collect(); client .assets() .delete() .ids(ids_to_delete) .execute() .await?; println!("Batch delete completed"); } // Verify deletion let remaining = client.assets().list().execute().await?; println!("\nRemaining assets: {}", remaining.len()); Ok(()) }