# Create Test Action Mapping $ErrorActionPreference = "Stop" Write-Host "Creating test action mapping..." -ForegroundColor Cyan # Login $loginBody = @{ username = "admin" password = "admin123" } | ConvertTo-Json $loginResponse = Invoke-RestMethod -Uri "http://localhost:8000/api/v1/auth/login" ` -Method POST ` -Body $loginBody ` -ContentType "application/json" $token = $loginResponse.access_token Write-Host "[OK] Logged in" -ForegroundColor Green # Create action mapping $headers = @{ "Authorization" = "Bearer $token" "Content-Type" = "application/json" "accept" = "application/json" } $mappingBody = @{ name = "Motion Detection Auto-Route" description = "Route camera 101038 to monitor 1 when motion is detected" input_action = "VMD_Start(101038)" output_actions = @("CrossSwitch(101038, 1, 0)") enabled = $true } | ConvertTo-Json Write-Host "[OK] Creating mapping..." -ForegroundColor Yellow try { $newMapping = Invoke-RestMethod -Uri "http://localhost:8000/api/v1/action-mappings" ` -Method POST ` -Headers $headers ` -Body $mappingBody Write-Host "[OK] Mapping created successfully!" -ForegroundColor Green Write-Host "" Write-Host "Mapping Details:" -ForegroundColor Cyan Write-Host " ID: $($newMapping.id)" -ForegroundColor White Write-Host " Name: $($newMapping.name)" -ForegroundColor White Write-Host " Input: $($newMapping.input_action)" -ForegroundColor White Write-Host " Outputs: $($newMapping.output_actions -join ', ')" -ForegroundColor White Write-Host " Enabled: $($newMapping.enabled)" -ForegroundColor White Write-Host "" # Verify by fetching all mappings Write-Host "Verifying - fetching all mappings..." -ForegroundColor Yellow $allMappings = Invoke-RestMethod -Uri "http://localhost:8000/api/v1/action-mappings" ` -Method GET ` -Headers $headers Write-Host "[OK] Total mappings in database: $($allMappings.total_count)" -ForegroundColor Green } catch { Write-Host "[ERROR] Failed to create mapping" -ForegroundColor Red Write-Host "Error: $($_.Exception.Message)" -ForegroundColor Red Write-Host "Response: $($_.ErrorDetails.Message)" -ForegroundColor Red }